jquery jqgrid propery with dot operator

我有一个带有点“。”属性的json。 操作员在里面。 当我试图渲染我的网格时,它显示为空白(没有任何错误)。

这是我的JSON:

{ "total":1, "page":1, "records":2, "rows":[{ "id":2110040, "cell":{ "function.code":"dsadad", "service.name":"dsadasda" } }, { "id":2115040, "cell":{ "function.code":"iuiyuiy", "service.name":"iyuiyuiy" } } ] } 

这是我的colModel

 colModel : [ { name : 'service.name', search : 'true', editable : true, //index : 'service.name', width : 200, jsonmap : "cell.service.name" }, { name : 'function.code', search : 'true', editable : true, sortable:true, //index : 'function.code', width : 200, jsonmap : "cell.function.code" }], 

JSON读者是:

 jsonReader : { repeatitems : false, root : "rows", cell : "cell", id : "id", page : "page", records : "records" }, 

请帮忙,我在这里失踪了什么?

谢谢!

我发现你的问题很有趣。 它接近这里描述的问题,但是在JSON而不是XML的情况下。

问题是jqGrid尝试读取关于obj.cell.function.code而不是obj.cell['function.code'] 。 要让jqGrid正确读取数据,您可以使用函数作为jsonmap

 colModel: [ { name: 'service_name', search: 'true', editable: true, width: 200, jsonmap: function (obj) { return obj.cell['service.name']; } }, { name: 'function_code', search: 'true', editable: true, sortable: true, width: 200, jsonmap: function (obj) { return obj.cell['function.code']; } } ] 

如何在演示中看到该方法的工作原理。

试试这个

 colModel : [ { name : 'service.name', search : 'true', editable : true, //index : 'service.name', width : 200, jsonmap : 'cell["service.name"]' }, { name : 'function.code', search : 'true', editable : true, sortable:true, //index : 'function.code', width : 200, jsonmap : 'cell["function.code"]' }],