2012-12-24 3 views
0

jqgrid에 내 데이터를 표시 할 수 없습니다.jqGrid 데이터로드 문제

jqgrid won't load json data

내 데이터는 다른,하지만 실질적으로 그렇게 :

{"records":95,"page":1,"total":1,"rows":[{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"},{"Report":"f_cn_08","File":"F_CONTR.PBL"}]} 

내가 다시 열 수있는 동일한 문제가 싫어,하지만 나는이 일 예에서 정확히 동일한 코드를 사용하고 나에게 매우 실망 스럽다.

편집 : 여기 내 코드입니다 :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>InfoMaker Monitor</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/redmond/jquery-ui.css" /> 
    <link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.1/css/ui.jqgrid.css" /> 
    <style type="text/css"> 
     html, body { font-size: 75%; } 
    </style> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> 
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.1/js/i18n/grid.locale-en.js"></script> 
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.3.1/js/jquery.jqGrid.src.js"></script> 

    <script type="text/javascript"> 
    //<!CDATA[ 
     jQuery(function() { 
      'use strict'; 
      jQuery("#jsonmap").jqGrid({ 
      url: 'http://localhost:8888/nancy/readasjson' 
      ,datatype: 'json' 
      ,ajaxGridOptions: { contentType: 'application/json; charset=utf-8' } 
      // see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data 
      ,jsonReader : { 
       page: "page" 
       , total: "total" 
       , records: "records" 
       , rows: "rows" 
       ,cell: "cell" 
       ,id: "id", 
       } 
      ,colNames: ['Report','File'] 
      ,colModel :[ 
       {name:'Report' ,index:'Report', width:55} 
       ,{name:'File',index:'File', width:55} 
      ] 
      ,rowNum:10 
      ,rowList:[10,20,30] 
      ,viewrecords: true 
      ,loadComplete: function() { 
       console.log("Load Complete"); 
       //console.log("URI: " + jQuery("#jsonmap").jqGrid.datatype); 
      } 
      ,loadError: function(xhr,st,err) { 
       console.log(xhr.statusText); 
       //$("#jsonmapMessage").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText); 
      } 
      ,width: '900' 
      ,height: 'auto'//'300' 
      ,caption: 'My first grid' 
      }); 
      jQuery("#jsonmap").jqGrid('navGrid','#pjmap',{edit:true,add:false,del:false}); 
     }); 
    //]]> 
    </script> 
</head> 
<body> 
    <table id="jsonmap"><tr><td></td></tr></table> 
    <div id="pjmap"></div> 
</body> 
</html> 

그리고 여기에 데이터가 지금 모습입니다 : 내가있는 jqGrid 소스 포크와 일부 CONSOLE.LOG 메시지를 추가 안넘어

{"records":10,"page":1,"total":1,"rows":[{"id":61,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":62,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":63,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":64,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":65,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":68,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":77,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":79,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":80,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}},{"id":81,"cell":{"Report":"f_cn_08","File":"F_CONTR.PBL"}}]} 

그것! 메시지가 없으면서 신비스럽게 실패하는 것은 입양에 커다란 장벽이되기 때문입니다.

+0

방화범 소리는 무엇이라고 말합니까? 코드는 어떻게 생겼습니까? –

+0

크롬 디버깅을 사용 중이며 불평하지 않습니다. –

+0

코드없이 도울 수 없습니다. –

답변

0

사용하는 JSON 데이터가 형식으로 the referenced question과 같으므로 jqGrid가 사용자의 데이터를 읽을 수 없습니다. jsonReader 옵션은 jqGrig의 입력 데이터 형식을 설명합니다. rows 배열에 이름이 지정된 속성이있는 객체가 들어있는 경우 jsonReader: {repeatitems: false}을 사용해야합니다. 이 경우 colModel 매개 변수의 열은 name: "Report"name: "File"이어야합니다.

JSON 데이터의 다음 문제 - 행 항목에 대한 정보가 id입니다. 이 경우 jqGrid는 정수 값 1, 2, 3 ...을 ROWID로 사용합니다. 이러한 id의 자동 생성은 페이지 당 하나의 그리드에만 유용합니다. 두 번째 눈금에는 ID 중복이 있습니다. 따라서 추가 입력란 id을 배열 rows의 모든 항목에 JSON 입력에 포함하는 것이 좋습니다.

+0

감사합니다. "id"필드를 추가 할 때 colModel에이 필드를 포함해야합니까? –

+0

가까이에 있습니다. 제안 된대로 jsonReader를 설정 한 다음 모드에 "id"필드도 추가했습니다. 해당 필드를 colModel에 포함해야합니까? 이제이 오류가 발생합니다. Uncaught TypeError : 정의되지 않은 '0'속성을 읽을 수 없습니다. –

+0

@DanielWilliams :'colModel'에'id '를 추가 할 필요가 없습니다. 그리드의 ''요소의 id 속성의 값을 할당하는 데에만 사용됩니다. 그래도 오류가 발생하면 질문에 현재 코드를 추가해야합니다. – Oleg