jqGrid在尝试加载json时给出异常

时间:2010-07-09 15:15:49

标签: jquery json jqgrid

我的网站上有以下html:

<link type="text/css" href="/Styles/ui-lightness/jquery-ui-1.8.2.custom.css" rel="Stylesheet" />
<link type="text/css" href="/Styles/ui.jqgrid.css" rel="Stylesheet" />
<script type="text/javascript" src="/Scripts/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="/Scripts/jquery-ui-1.8.2.min.js" ></script>
<script type="text/javascript" src="/Scripts/grid.locale-en.js" ></script>
<script type="text/javascript" src="/Scripts/jquery.jqGrid.min.js" ></script><link type="text/css" rel="Stylesheet" href="Styles/Site.css" />

...

<script type="text/javascript">
    $(document).ready(function () {
        jQuery("#tblScheduledReleases").jqGrid({
            url: '/Release/GetScheduledReleases',
            datatype: "json",
            mtype: 'POST',
            colNames: ['Id', 'Version', 'Name', 'Scheduled Date'],
            colModel: [
                { name: 'id', width: 55 },
                { name: 'version', width: 90 },
                { name: 'name', width: 100 },
                { name: 'date', width: 90 }
                  ],
            autowidth: true,
            sortname: 'date',
            viewrecords: true,
            sortorder: "desc",
            caption: "Scheduled Releases"
        });
    });
</script>

....

<table id="tblScheduledReleases"></table>
<div id="divScheduledPager"></div>

现在加载网格时显示正确的列,然后显示Loading消息。但是,它永远停留在装载部分。打开chrome控制台会显示以下错误:

Uncaught TypeError: Cannot read property '0' of undefined in jquery.jqGrid.min.js:14

这是由jqGrid请求的我的网络服务器返回的Json:

{
  "page":"1",
  "total":"1",
  "records":6,
  "rows":[
    {"id":"37","version":"4.14.9.1","name":"4.14 Patch 8","date":"2010-07-08"},
    {"id":"39","version":"4.15.4.1","name":"4.15 Patch 3","date":"2010-07-08"},
    {"id":"36","version":"4.13.11.1","name":"4.13 Patch 11","date":"2010-07-15"},
    {"id":"40","version":"4.15.5.1","name":"4.15 Patch 4","date":"2010-07-22"},
    {"id":"38","version":"4.14.10.1","name":"4.14 Patch 9","date":"2010-07-22"},
    {"id":"30","version":"4.16.1.1","name":"4.16 Release","date":"2010-07-30"}
  ]
}

为什么我会收到此异常?

1 个答案:

答案 0 :(得分:34)

你应该包括

 jsonReader : { repeatitems: false }

在jqGrid参数中。