admin管理员组文章数量:1289634
may I know how to push var obj= [{}]
in .each
? for example like this.
$.each(maintasks_row, function(index, maintasks_val) {
obj.push([{
"name" : maintasks_val.task_name,
"desc" : "",
"values" : [{
"from" : "/Date("+maintasks_val.time_start+")/",
"to" : "/Date("+maintasks_val.time_end+")/",
"label": maintasks_val.task_name,
"customClass" : "ganttRed"
}]
}]);
});
I'm using this for $(".gantt").gantt({source: obj});
On this site the var data
is [{}]
is this an object? and how can I insert it?
thank you
may I know how to push var obj= [{}]
in .each
? for example like this.
$.each(maintasks_row, function(index, maintasks_val) {
obj.push([{
"name" : maintasks_val.task_name,
"desc" : "",
"values" : [{
"from" : "/Date("+maintasks_val.time_start+")/",
"to" : "/Date("+maintasks_val.time_end+")/",
"label": maintasks_val.task_name,
"customClass" : "ganttRed"
}]
}]);
});
I'm using this for $(".gantt").gantt({source: obj});
On this site the var data
is [{}]
is this an object? and how can I insert it?
thank you
Share Improve this question edited Mar 9, 2014 at 15:32 zoranc 2,4561 gold badge22 silver badges34 bronze badges asked Mar 9, 2014 at 14:05 Vincent815Vincent815 1391 gold badge2 silver badges9 bronze badges 3-
1
You're adding single-element arrays prising an object onto
obj
here; is that what you want? – Ja͢ck Commented Mar 9, 2014 at 14:08 - You said you want to push object but inserting array of object, what you want to do? – Suman Bogati Commented Mar 9, 2014 at 14:09
-
yes, i want to insert it like this
var data = [ { "name": " Step A ","desc": "→ Step B" ,"values": [{"id": "b0", "from": "/Date(1320182000000)/", "to": "/Date(1320301600000)/", "desc": "Id: 0<br/>Name: Step A", "label": " Step A", "customClass": "ganttRed", "dep": "b1"}] }];
– Vincent815 Commented Mar 9, 2014 at 14:09
1 Answer
Reset to default 7.push
does not require you delcare it as an array ( like you tried obj.push([{
- unless of course you are pushing an array into an array
Just simply ...
obj.push({"name" : maintasks_val.task_name, ..
adds a new single item intto the array
Update as ment , yes, declare obj
as a typeof
array first
var obj=[];
This is now the same as the data
array you have shown in your docs example - and we can now .push()
into it.
本文标签: javascripthow to push an object like this in jqueryStack Overflow
版权声明:本文标题:javascript - how to push an object like this in jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741479617a2381088.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论