我有下面的json,我想要显示到我的jqgrid上。我有以下jsonReader
jsonReader : {
repeatitems: false,
root: "abc",
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
},
专栏模型:
colModel:[
{name:'num'},
{name:'seq'},
{name:'status'},
{name:'transTime'},
{name:'sd'},
{name:'total'},
{name:'xys'}
],
JSON:
{
"xys": 3,
"abc": [
{
"time": null,
"num": "1234",
"seq": 2,
"status": "X",
"transTime": null
},
{
"time": null,
"num": "4567",
"seq": 1,
"status": "Y",
"transTime": null
}
],
"sd": "7895",
"total": 5
}
只有num,seq和status填充了数据,但没有transTime,sd,total和xys
任何想法和指针?
答案 0 :(得分:0)
如果您必须读取JSON数据并且无法更改服务器端的数据,您可以对从客户端的服务器返回的数据进行小的转换 beforeProcessing
回调内部。 The demo执行此操作并显示以下结果
它使用以下代码
loadonce: true,
jsonReader: { root: "abc" },
beforeProcessing: function (data) {
var root = data.abc, i, item, cItems = root.length;
for (i = 0; i < cItems; i++) {
item = root[i];
item.sd = data.sd;
item.id = $.jgrid.randId();
item.total = data.total;
item.xys = data.xys;
if (item.transTime === null) {
item.transTime = "null";
}
}
}