jqgrid json reader for arcgis服务器查询结果

时间:2012-03-06 14:57:54

标签: json jqgrid jsonp arcgis

我需要在jqgrid中绘制像these这样的数据的json阅读器是什么类型的?

谢谢!

1 个答案:

答案 0 :(得分:0)

您有关于jsonReader的奇怪问题和所有问题。在目前的情况下,您可以使用

jsonReader: {
    root: 'features',
    repeatitems: false
}

读取数据。 The demo显示结果如何:

enter image description here

更新:我的理解,您真正要做的是调用一些外部网址,为您提供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的工作原理。