如何映射一个 json 响应,该响应在字段名称中既有点又具有值子元素
How to map a json response that has both dot in the field name and has a value sub element
我有一个 JSON 看起来像这样:
{"resolution": [
{
"resolution.resolution_id": {"val": "28"},
"resolution.resolution_comment": {"val": "sdfsdfsdfsdfs"},
"resolution.resolved_by_user": {"val": "XXX"}
},
{
"resolution.resolution_id": {"val": "28"},
"resolution.resolution_comment": {"val": "sdfsdfsdfsdfs"},
"resolution.resolved_by_user": {"val": "YYY"}
}
]}
和一个 JQGrid 定义:
$(newTable).jqGrid({
url:"someurl",
mtype: 'GET',
datatype: "json",
height: 250,
colNames:['id'],
colModel:[
{
name:'resolution.resolution_id',index:'resolution.resolution_id',sorttype:'string', width:200
},
],
rowNum: 10000,
pager:'#pager',
toppager: true,
viewrecords: true,
sortname: 'resolution_id',
jsonReader:{repeatitems: false,root:'resolution'},
multiselect: true,
gridview: true,
caption: "Resolution"
})
如何设置 JSON 地图使其可以读取 resolution.resolution_id?
我试过jsonmap:resolution的各种组合。resolution_id.val
也试过
jsonmap:function(row){return row["val"]}
无果
尝试使用此 colModel 和以下 jsonmap:
colModel:[
{
name:'resolution.resolution_id',
index:'resolution.resolution_id',
jsonmap : function (a) { var v = a["resolution.resolution_id"]; return v.val; },
sorttype:'string',
width:200
},
....
]
或简单
jsonmap : function (a) { return a["resolution.resolution_id"].val; },
我有一个 JSON 看起来像这样:
{"resolution": [
{
"resolution.resolution_id": {"val": "28"},
"resolution.resolution_comment": {"val": "sdfsdfsdfsdfs"},
"resolution.resolved_by_user": {"val": "XXX"}
},
{
"resolution.resolution_id": {"val": "28"},
"resolution.resolution_comment": {"val": "sdfsdfsdfsdfs"},
"resolution.resolved_by_user": {"val": "YYY"}
}
]}
和一个 JQGrid 定义:
$(newTable).jqGrid({
url:"someurl",
mtype: 'GET',
datatype: "json",
height: 250,
colNames:['id'],
colModel:[
{
name:'resolution.resolution_id',index:'resolution.resolution_id',sorttype:'string', width:200
},
],
rowNum: 10000,
pager:'#pager',
toppager: true,
viewrecords: true,
sortname: 'resolution_id',
jsonReader:{repeatitems: false,root:'resolution'},
multiselect: true,
gridview: true,
caption: "Resolution"
})
如何设置 JSON 地图使其可以读取 resolution.resolution_id?
我试过jsonmap:resolution的各种组合。resolution_id.val
也试过
jsonmap:function(row){return row["val"]}
无果
尝试使用此 colModel 和以下 jsonmap:
colModel:[
{
name:'resolution.resolution_id',
index:'resolution.resolution_id',
jsonmap : function (a) { var v = a["resolution.resolution_id"]; return v.val; },
sorttype:'string',
width:200
},
....
]
或简单
jsonmap : function (a) { return a["resolution.resolution_id"].val; },