I have a list of objects that I return using webservice. And I try to build an array like you can see below.
$.each(items, function (index, item开发者_高级运维) {
i[index] = '[' + item.Name + ',' + item.Count + ']';
});
I need to build array like
var t = [['Mushrooms', 3], ['Onions', 1], ['Olives', 1], ['Zucchini', 1], ['Pepperoni', 2], ];
but it's not working for me for some reason. It should not be string. It needs to has the same format as you see in example. Otherwise it will not work.
Here is the rest of the code I need to add it to table
var t = [['High', 3], ['Onions', 1], ['Olives', 1], ['Zucchini', 1], ['Pepperoni', 2], ];
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows(t);
Don't use quotes:
var t = [];
$.each(items, function (index, item) {
t[index] = [item.Name, item.Count];
});
I also added the code to initialize t
(assuming you want that instead of i
).
$.each(items, function (index, item) {
i.push([item.Name, item.Count]);
});
remove the '
characters and you will be an actual array.
精彩评论