我的目标是能够产生完全像这样的东西。jQuery .each()创建对象数组
var data = google.visualization.arrayToDataTable([
['Year', 'Cost'],
['2004', 1000],
['2005', 1170],
['2006', 660],
['2007', 1030]
]);
但我试图得到它的使用由JSON
{
"uid": 1,
"name": "Cost",
"data": [
{
"year": 2009,
"cost": 640
},
{
"year": 2010,
"cost": 620
},
{
"year": 2011,
"cost": 600
},
{
"year": 2012,
"cost": 620
}
]
}
产生的数据,并通过使用这个jQuery
$.getJSON("js/cost.json", function(d) {
console.log(d.data);
var items = [];
$.each(d.data, function(k, v) {
console.log(v.cost);
console.log(v.year);
items.push("['"+v.year+"',"+v.cost+"]");
});
console.log(items);
});
但是我注意到的是,做它作为一个字符串被推送,什么是正确的方式来推送对象到一个数组,所以我可以得到这个工作。
我不知道是什么让你把摆在首位的字符串。我的意思是,看起来你知道什么是阵列,因为你正在使用它们。 –