【问题标题】:jqgrid json reader for arcgis server query results用于 arcgis 服务器查询结果的 jqgrid json 阅读器
【发布时间】:2012-03-24 01:45:59
【问题描述】:

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

谢谢!

【问题讨论】:

    标签: json jqgrid jsonp arcgis


    【解决方案1】:

    您有一些奇怪的问题以及关于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 工作的地方。

    【讨论】:

    • 谢谢奥列格。我的工作是关于 GIS 和 web 开发,其中一个重要的部分是在网格中渲染地理空间数据,所以我认为我的问题并不那么奇怪......可能我必须更准确地阅读 json 阅读器文档。再次感谢您
    • @user781065:不客气!我忘了提到,我在答案中还使用了jsonmap,比如jsonmap: 'attributes.NAME'。官方文档你可以找到here。对于jsonReader as function,几乎可以读取任何 JSON 输入。此外,有时使用beforeProcessing 回调会有所帮助。如果问题得到解决,您可以将答案标记为“已接受”。
    • Oleg,您尝试过我在第一篇文章中提供的网址吗?使用它,网格始终为空,firebug 为请求返回状态 200 OK,但为红色...
    • @user781065:你是指哪个URL?你的意思是哪个帖子?这个问题还是您关于 stackoverflow 的第一个问题?在我的演示中,我使用了您的数据的精确副本。
    • 嗨,Oleg,看看这里的演示:dl.dropbox.com/u/1070973/jqgrid_reader/index2.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-27
    • 2023-02-16
    • 1970-01-01
    相关资源
    最近更新 更多