Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

jquery jqgrid propery with dot operator

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...