0

jqgrid に表示するデータを取得できません。この実例とまったく同じコードを使用しています。

jqgrid は json データをロードしません

私のデータは異なりますが、実質的にはそうではありません:

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

データは次のようになります。

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

jqgrid ソースをフォークして、console.log メッセージをいくつか追加したくなります。何のメッセージもなく不思議に失敗することは、採用への大きな障壁だからです。

4

1 に答える 1

0

使用する JSON データは、参照されている質問のように別の形式であるため、jqGrid はデータを読み取ることができません。オプションは、jqGrig の入力データの形式を記述します。配列に名前付きプロパティを持つオブジェクトが含まれている場合は、 を使用する必要があります。パラメータにとの列が必要な場合。jsonReaderrowsjsonReader: {repeatitems: false}colModelname: "Report"name: "File"

JSON データの次の問題 -id行の項目に関する情報がありません。この場合、jqGrid は整数値 1、2、3... を行 ID として使用します。このような ID の自動生成は、ページごとに 1 つのグリッドに対してのみ有効です。2 番目のグリッドには ID の重複があります。そのため、JSON 入力idの配列のすべての項目に追加のプロパティを含めることをお勧めします。rows

于 2012-12-25T19:45:51.497 に答える