【问题标题】:JSON.parse: unexpected character exception on jqgridJSON.parse:jqgrid 上的意外字符异常
【发布时间】:2013-07-04 10:46:56
【问题描述】:

我在尝试读取 JQGrid 中的本地 JSON 时收到 JSON.parse: 意外字符异常。

<script type="text/javascript">

var jsondata =  { 
      "totalpages": "1", 
      "currpage": "1",
      "totalrecords": "2",
      "invdata" : [
        {"name":"New York City", "country":"USA", "continent":"NorthAmerica"},
        {"name":"Paris", "country":"France", "continent":"Europe"}

      ]
    };

$(document).ready(function() {
$("#grid").jqGrid({ data: jsondata,
                    datatype: "json",
                    colNames: ["Name", "Country", "Continent"],
                    colModel: [{
                        name: 'name',
                        index: 'name',
                        editable: true, 
                    }, {
                        name: 'country',
                        index: 'country',
                        editable: true,
                    }, {
                        name: 'continent',
                        index: 'continent',
                        editable: true,
                    }],
                    pager: '#pager',
                    jsonReader : {
                        root:"invdata",
                        page: "currpage",
                        total: "totalpages",
                        records: "totalrecords",
                        repeatitems: false,
                        id: "0"
                     },
                    caption:"Dynamic hide/show column groups"
            }).navGrid("#pager",{edit:false,add:false,del:false});

    jQuery("#hc").click( function() { jQuery("#grid").jqGrid('hideCol',["continent"]); }); 
    jQuery("#sc").click( function() { jQuery("#grid").jqGrid('showCol',["continent"]); });


});



</script>

我尝试在 jqgrid Wiki 中查找,但仍然无法找出问题所在。 jsonReader 有问题吗?我检查了相关问题,但没有太大帮助。

【问题讨论】:

    标签: json jqgrid


    【解决方案1】:

    不要将“jsondata”作为参数提供给 jqgrid 的“data”,而是提供 data : jsondata.invdata

    【讨论】:

    猜你喜欢
    • 2017-09-27
    • 1970-01-01
    • 2020-02-04
    • 2021-10-20
    • 2018-11-18
    • 2020-08-12
    • 2020-03-07
    • 2022-11-07
    • 2020-04-07
    相关资源
    最近更新 更多