2010-07-09 46 views
9

我已經在我的網站下面的HTML:的jqGrid給人異常,當JSON是試圖加載

<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消息。但是,它永久卡在裝載部分。開放鉻控制檯顯示以下錯誤:

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

下面是JSON的被我的服務器返回由jqGrid的要求:

{ 
    "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"} 
    ] 
} 

爲什麼會出現這種異常?

回答

33

你應該包括

jsonReader : { repeatitems: false } 
在jqGrid的參數

+0

真棒工作! – KallDrexx 2010-07-09 15:45:52

+2

它必須工作! 'repeatitems'默認值爲'true',jqGrid嘗試讀取所有數字,所以不是像{「id」:「37」,「version」:「4.14.9.1」,「name」: 「4.14 Patch 8」,「date」:「2010-07-08」}例如,你應該有array [「37」,「4.14.9.1」,「4.14 Patch 8」,「2010-07-08」]。 – Oleg 2010-07-09 16:07:55

+0

再次來自Oleg的網格jqGrid響應。 Thx男人! – Steven 2016-03-10 11:52:27

相關問題