对象上的jqGrid JSON表示法 [英] jqGrid JSON notation on objects

查看:76
本文介绍了对象上的jqGrid JSON表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有!
我的jqGrid中有一列是空的.
但是我在chrome控制台上检查了对象,没关系.

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

colModel定义

colModel:[
    {name:'id',index:'id', width:55,editable:false,editoptions:{readonly:true,size:10},hidden:true},
    {name:'firstName',index:'firstName', width:100,searchoptions: { sopt: ['eq', 'ne', 'cn']}},
    {name:'lastName',index:'lastName', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
    {name:'books[0].nome',index:'books[0].nome', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
    {"formatter":"myfunction", formatoptions:{baseLinkUrl:'/demo/{firstName}|view-icon'}}
]

JSON响应

{
    "total": "10",
    "page": "1",
    "records": "3",
    "rows": [
        {
            "id": 1,
            "firstName": "John",
            "lastName": "Smith",
            "books": [{"nome": "HeadFirst"}]
        },
        {
            "id": 2,
            "firstName": "Jane",
            "lastName": "Adams",
            "books": [{"nome": "DalaiLama"}]
        },
        {
            "id": 35,
            "firstName": "Jeff",
            "lastName": "Mayer",
            "books": [{"nome": "Bobymarley"}]
        }
    ]
}

Chrome控制台检查对象

rowdata.books[0].nome
"HeadFirst"

有人知道哪里有可能的把戏吗?

Any one know where theres are possibles trick?

谢谢!

推荐答案

您应仅将可在JavaScript中用作属性名称和CSS ID名称的名称用作colModelname属性的值.因此name:'books[0].nome'的使用不是一个好主意.

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.

要解决您的问题,可以使用jsonmap.例如,您可以使用点名称转换:

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

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

在更复杂的情况下,可以将函数用作jsonmap的值.例如

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;
    }, ...

您可以在其他旧答案中找到有关jsonmap用法的更多代码示例:此处此处此处此处此处.

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

这篇关于对象上的jqGrid JSON表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆