jquery jqgrid propery with dot operator

守給你的承諾、 提交于 2019-11-27 07:36:41

问题


I have a json with a property having dot "." operator in it. When im trying to render my grid, it comes up as blank (without any errors).

Here's my 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"

                }
            }
        ]
    }

this is my 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 reader is:

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

Please help,what am i missing here ??

Thanks!


回答1:


I find you question interesting. It's close to the problem described here, but in case of JSON instead of XML.

The problem is that jqGrid try to read rows with respect of obj.cell.function.code instead of obj.cell['function.code']. To let jqGrid to read the data correctly you can use functions as the 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'];
        }
    }
]

How you can see on the demo the approach work.




回答2:


Try this

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


来源:https://stackoverflow.com/questions/6902936/jquery-jqgrid-propery-with-dot-operator

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