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

查看:13
本文介绍了对象上的 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.

col模型定义

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?

谢谢!

推荐答案

colModelname 属性的值只能用作可用作JavaScript 中的属性名称和 CSS id 名称.所以 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天全站免登陆