具有动态json数据的Slickgrids [英] Slickgrids with dynamic json data
本文介绍了具有动态json数据的Slickgrids的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面给出的JSON格式的数据,需要使用cols中的数据和值中的行来填充平滑的网格列. >
I ve data in the JSON format given below,need to populate the slick grid columns with the data from cols and rows from values.. Could u please help me with the loops required to do so ....
var response = { "cols" : ["name", "Precentage", "Year", "Amount"],
"rows": [{
"flag": true,
"values": [" name1", "Precentage1", "year1", "Amount1"]
}
推荐答案
也许有更好的方法,但是您可以手动遍历并构建数据数组,如下所示:
There may be a better way to do this, but you could just loop through and build the data array by hand, something like this:
var colName;
var data = [];
for (var i = 0; response.cols.length; i++) {
colName = response.cols[i];
for (var j = 0; response.values.length; i++) {
if (i === 0) data[j] = {};
data[j][colName] = response.values[i];
}
}
然后可以使用grid.setData(data)
将数据传递到网格中.
You can then use grid.setData(data)
to pass the data into the grid.
这篇关于具有动态json数据的Slickgrids的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文