请看这个例子:JsFiddle
问:我有以下JSON Array
y= [ {"LngTrend":15,"DblValue":10,"DtmStamp":1358226000000},
{"LngTrend":16,"DblValue":92,"DtmStamp":1358226000000},
{"LngTrend":17,"DblValue":45,"DtmStamp":1358226000000},
{"LngTrend":18,"DblValue":87,"DtmStamp":1358226000000},
{"LngTrend":15,"DblValue":10,"DtmStamp":1358226060000},
{"LngTrend":16,"DblValue":87,"DtmStamp":1358226060000},
{"LngTrend":17,"DblValue":45,"DtmStamp":1358226060000},
{"LngTrend":18,"DblValue":92,"DtmStamp":1358226060000} ]
我试图通过DtmStamp
最终得到这样的东西来对这些对象进行分组:
x = [[1358226000000,10,92,45,87],[1358226060000,10,87,45,92], .......]
换句话说:
x[0][0] = y[0].DtmStamp ;
x[0][1] = y[0].LngTrend ;
x[0][2] = y[1].LngTrend ;
x[0][3] = y[2].LngTrend ;
x[0][4] = y[3].LngTrend ;
不幸的是,它以我不想要的东西结束。
这是我到目前为止所尝试的:
var dataTrendArray = [];
$.each(x, function (index, value) {
var trendArray = [];
if (index % 4 == 0) {
trendArray.push(x[index].DtmStamp);
for (var i = 0; i < 4; i++) {
index = eval(index + i);
trendArray.push(x[index].DblValue);
}
}
console.log(trendArray) ;
dataTrendArray.push(trendArray);
});
有人可以帮助我走上正确的道路吗?