jqGrid JSON notation on objects

后端 未结 2 1007
渐次进展
渐次进展 2020-12-21 22:34

there!
I´ve one column in my jqGrid that is empty.
But i checked the object on chrome console and thats fine.

colModel definition



        
相关标签:
2条回答
  • 2020-12-21 23:11

    name is intended to be a unique name for the row, not a reference to a JSON object. From the jqGrid colModel options documentation:

    Set the unique name in the grid for the column. This property is required. As well as other words used as property/event names, the reserved words (which cannot be used for names) include subgrid, cb and rn.

    You can also observe how .name is used within grid.base.js - for example:

    var nm = {},
    ...
    nm = $t.p.colModel[i].name;
    ...
    res[nm] = $.unformat.call($t,this,{rowId:ind.id, colModel:$t.p.colModel[i]},i);
    

    Anyway, to get back to your question I think you will have better luck by passing down the book name directly - as strings and not objects - and referencing it by name as something like bookName.

    0 讨论(0)
  • 2020-12-21 23:16

    You should use as the value of name property of colModel only the names which can be used as property name in JavaScript and as CSS id names. So the usage of name:'books[0].nome' is not good idea.

    To solve your problem you can use jsonmap. For example you can use dotted name conversion:

    {name: 'nome', jsonmap: 'books.0.nome', ...
    

    In more complex cases you can use functions as the value of jsonmap. For example

    {name: 'nome', jsonmap: function (item) {
            return item.books[0].nome;
        }, ...
    

    You can find some more code examples about the usage of jsonmap in other old answers: here, here, here, here, here.

    0 讨论(0)
提交回复
热议问题