JqGrid无法将JSON数据与“点"绑定在一起. [英] JqGrid not able to bind JSON data with "dot"
问题描述
我有一个试图绑定到JQgrid的服务器的JSON响应.但是,响应是对象名称中包含点"的JSON字符串.我无法使JQGrid与点"一起工作
I have a JSON response from server which I am trying to bind to JQgrid. However, the response is a JSON string has "dot" as a part of the object name. I am unable to get the JQGrid work with the "dot"
这是我面临的问题的样本提琴 http://jsfiddle.net/sharathchandramg/rpdfrb0L/2/
Here is the sample fiddle for the problem I am facing http://jsfiddle.net/sharathchandramg/rpdfrb0L/2/
$("#grid").jqGrid({
data: data,
datatype: "local",
height: 250,
colNames: ['Name', 'Cluster', 'Location'],
colModel: [{
name: 'name',
width: 120
}, {
name: 'metrics.cluster.first.value',
width: 60,
jsonmap: function (obj) {
return obj.metrics['cluster.first'].value
}
}, {
name: 'metrics.location-latitude.value',
width: 60
}, ],
caption: "Example"
});
如小提琴所示,即使使用jsonmap,我也无法绑定属性"cluster.first".而如果属性名称为"location-latitude",则网格可以正常工作.
As shown the fiddle, I am not able to bind the property "cluster.first" even while using jsonmap. Whereas if the property name is "location-latitude" the grid works fine.
让我知道我在做错什么.
Let me know what I am doing wrong.
推荐答案
原因很简单.如果在jqGrid 4.6中使用datatype: "local"
,则将忽略属性jsonmap
.我在免费jqGrid 中更改了行为(请参见
The reason is very easy. The property jsonmap
will be ignored in case of usage datatype: "local"
in jqGrid 4.6. I changed the behavior in free jqGrid (see the wiki). So one possible solution will be to use free jqGrid 4.8 or higher instead of jqGrid 4.6.
解决问题的另一种简单方法是使用datatype: "jsonstring"
.您可以验证
One more simple way to solve the problem will be usage of datatype: "jsonstring"
. You can verified
$("#grid").jqGrid({
datastr: data,
datatype: "jsonstring",
height: "auto",
colNames: ['Name', 'Cluster', 'Location'],
colModel: [{
name: 'name',
width: 120
}, {
name: 'metrics_cluster_first_value',
width: 60,
jsonmap: function (obj) {
return obj.metrics['cluster.first'].value
}
}, {
name: 'metrics_location_latitude_value',
jsonmap: 'metrics.location-latitude.value',
width: 60
}],
caption: "Example"
});
请参见 http://jsfiddle.net/OlegKi/rpdfrb0L/5/.您还可以看到我将所有colModel
项的name
属性更改为内部没有点.我建议始终遵循规则.
See http://jsfiddle.net/OlegKi/rpdfrb0L/5/. You can see additionally that I changed name
property of all colModel
items to have no dots inside. I recommend to follow the rule always.
这篇关于JqGrid无法将JSON数据与“点"绑定在一起.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!