【发布时间】:2012-03-24 01:45:59
【问题描述】:
我需要什么样的 json 阅读器在 jqgrid 中绘制像 these 这样的数据?
谢谢!
【问题讨论】:
我需要什么样的 json 阅读器在 jqgrid 中绘制像 these 这样的数据?
谢谢!
【问题讨论】:
您有一些奇怪的问题以及关于jsonReader 的所有信息。在当前情况下,您可以使用
jsonReader: {
root: 'features',
repeatitems: false
}
读取数据。 The demo 显示了结果的样子:
更新:据我所知,您真正想要做的是调用一些 external URL,它为您提供 JSON。由于安全原因,标准 Ajax 请求无法向另一台服务器执行(请参阅same origin policy)。幸运的是,服务器 sampleserver1.arcgisonline.com/ArcGIS 支持 JSONP 请求。因此,要使用外部数据填充网格,您可以使用以下代码
$('#grid').jqGrid({
url: 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4/query',
datatype: 'jsonp',
postData: $.param({
where: "1=1",
returnGeometry: false,
outFields: "ObjectID,NAME,STATE_NAME,CNTY_FIPS",
f: "json"
}),
colModel: [
{name: 'ObjectID', label: 'ID', width: 60, jsonmap: 'attributes.ObjectID'},
{name: 'NAME', label: 'Name', width: 150, jsonmap: 'attributes.NAME'},
{name: 'STATE_NAME', label: 'State', width: 120, jsonmap: 'attributes.STATE_NAME'},
{name: 'CNTY_FIPS', label: 'FIPS', width: 60, jsonmap: 'attributes.CNTY_FIPS'}
],
toppager: true,
jsonReader: {
root: 'features',
repeatitems: false
},
loadonce: true,
ignoreCase: true,
height: 'auto'
});
查看新的演示 here。
更新 2:为了能够使用本地搜索/过滤,应该修改上面的代码。最好把上面看到的postData替换成下面的参数
ajaxGridOptions: { cache: true },
prmNames: {search: null, nd: null, sort: null, rows: null, order: null, page: null},
postData: {
where: "1=1",
returnGeometry: false,
outFields: "ObjectID,NAME,STATE_NAME,CNTY_FIPS",
f: "json"
}
查看the corresponding demo filterToolbar 工作的地方。
【讨论】:
jsonmap,比如jsonmap: 'attributes.NAME'。官方文档你可以找到here。对于jsonReader as function,几乎可以读取任何 JSON 输入。此外,有时使用beforeProcessing 回调会有所帮助。如果问题得到解决,您可以将答案标记为“已接受”。
URL?你的意思是哪个帖子?这个问题还是您关于 stackoverflow 的第一个问题?在我的演示中,我使用了您的数据的精确副本。