带有点运算符的 jquery jqgrid 属性
Posted
技术标签:
【中文标题】带有点运算符的 jquery jqgrid 属性【英文标题】:jquery jqgrid propery with dot operator 【发布时间】:2011-10-17 16:36:21 【问题描述】:我有一个带有点“。”的属性的 json。运营商在里面。 当我尝试渲染我的网格时,它显示为空白(没有任何错误)。
这是我的 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"
]
这是我的 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 阅读器是:
jsonReader :
repeatitems : false,
root : "rows",
cell : "cell",
id : "id",
page : "page",
records : "records"
,
请帮忙,我在这里缺少什么?
谢谢!
【问题讨论】:
【参考方案1】:试试这个
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 对象的属性名称中使用点。您可以使用下划线或其他字符,如 $。看看这个link 不确定是 JSON 本身还是 JqGrid,因为在此之前我使用的是具有相同 JSON 格式的 flexigrid。无论如何,感谢您的帮助 Shankar。【参考方案2】:我觉得你的问题很有趣。它与here 描述的问题很接近,但在使用 JSON 而不是 XML 的情况下。
问题在于 jqGrid 尝试读取与 obj.cell.function.code
相关的行,而不是 obj.cell['function.code']
。要让 jqGrid 正确读取数据,您可以使用 函数作为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'];
]
您如何在the demo 上看到该方法的工作原理。
【讨论】:
@user620339:顺便说一句,another demo from your old answer 也可以。以上是关于带有点运算符的 jquery jqgrid 属性的主要内容,如果未能解决你的问题,请参考以下文章
JQuery JQGrid插件,如何通过链接点击模拟工具栏过滤操作?
基于jqgrid + ashx + nhibernate的分页