Slickgrids with dynamic json data

时间秒杀一切 提交于 2019-12-11 17:27:30

问题


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"]
}

回答1:


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];
  }
}

You can then use grid.setData(data) to pass the data into the grid.



来源:https://stackoverflow.com/questions/9902061/slickgrids-with-dynamic-json-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!