我正在努力将JSON结果转换为JQuery Array。请分享您的想法如何实现这一目标。
我的JSON结果如下:
0:{Business: "DS", DocCount: 18, NextReviewCount: 14, UptoDateCount: 1, OverDueCount: 3,url:"link1.html"}
1:{Business: "MRCSB", DocCount: 15, NextReviewCount: 14, UptoDateCount: 1, OverDueCount: 0,url:"link1.html"}
2:{Business: "PCGB", DocCount: 18, NextReviewCount: 12, UptoDateCount: 2, OverDueCount: 4,url:"link1.html"}
3:{Business: "PGB", DocCount: 10, NextReviewCount: 8, UptoDateCount: 1, OverDueCount: 1,url:"link1.html"}
我需要构建一个如下所示的数组:
var cXample=[
[[10,'PGB','link1.html'], [18,'DS','link1.html'], [15,'MRCSB','link1.html'], [18,'PCGB','link1.html']],
[[8,'PGB','link1.html'], [14,'DS','link1.html'], [14,'MRCSB','link1.html'], [12,'PCGB','link1.html']],
[[1,'PGB','link1.html'], [1,'DS','link1.html'], [1,'MRCSB','link1.html'], [2,'PCGB','link1.html']],
[[1,'PGB','link1.html'], [3,'DS','link1.html'], [0,'MRCSB','link1.html'], [4,'PCGB','link1.html']]
];
我需要将此结果显示为条形图。
答案 0 :(得分:0)
我找到了解决方案。
var array = $ .map(parseResult,function(item,index){
return [[item.DocCount,item.Business, item.url,0],[ item.NextReviewCount,item.Business, item.url,1],[ item.OverDueCount, item.Business, item.url,2],[item.UptoDateCount, item.Business, item.url,3]];
});
var arrayShortBySerl=array.sort(function(obj1, obj2) {
// Ascending: first age less than the previous
return obj1[3]- obj2[3];
});
for(var i = 0; i<((arrayShortBySerl.length)/ 4); i ++) { arryChart.push([arrayShortBySerl [i * 4],arrayShortBySerl [(i * 4)+1],arrayShortBySerl [(i * 4)+2],arrayShortBySerl [(i * 4)+3]]); }