0

次の構成でグリッドを作成しました

$.ajax({
        type: "POST",
        url: "populateAllRulesJson.action",
        data: "",
        dataType: "json",   
        success: function(result)
        {
             alert("SUCCESS ::: " + JSON.stringify(result.jSONResponseObject));
             data = JSON.stringify(result.jSONResponseObject);
             jQuery("#rulesTable").jqGrid({
                    url:"populateAllRulesJson.action",
                    datatype: "jsonstring", 
                    height: 'auto', 
                    width: 'auto', 
                    colNames:['Rule ID','Description', 'Geograph', 'Process', 'Rules Classification', 'Types', 'UDAC'], 
                    colModel:[ {name:'ruleID',index:'ruleID', width:65, sorttype:'int'}, 
                               {name:'description',index:'description', width:150}, 
                               {name:'geograph',index:'geograph', width:100},
                               {name:'process',index:'process', width:100},            
                               {name:'rulesClassification',index:'rulesClassification', width:100},
                               {name:'types',index:'types', width:100},
                               {name:'udac',index:'udac', width:100}
                             ], 
                    datastr : data,
                    jsonReader: { repeatitems: false },
                    rowNum:10, 
                    rowList : [10,20,30], 
                    loadonce:true, 
                    mtype: "GET", 
                    rownumbers: true, 
                    rownumWidth: 10, 
                    gridview: true, 
                    pager: '#rulesDivPager', 
                    sortname: 'ruleID', 
                    viewrecords: true, 
                    sortorder: "asc", 
                    caption: "Searching Rules ..."

                });
        },
        error: function(x, e)
        {
            alert(x.readyState + " "+ x.status +" "+ e.msg);
        }

});

次の JSON オブジェクトをグリッドに送信しています。しかし、グリッドには 4 つの空白行が表示されています。

{
"total":2,
"page":1,
"records":7,
"rows":[{"id":"1","cell":"{\"ruleID\":\"43\",\"description\":\"Images, text and voice over should synchronize as best as possible.\",\"geograph\":\"Yell US\",\"process\":\"Photomotion\",\"rulesClassification\":\"Image\",\"types\":\"New\",\"udac\":\"NPM\"}"},
{"id":"2","cell":"{\"ruleID\":\"48\",\"description\":\" For profile pages UDAC Mismatch in a Control sheet can be ignored.\",\"geograph\":\"Yell US\",\"process\":\"Profile Pages\",\"rulesClassification\":\"Copysheet\",\"types\":\"New\",\"udac\":\"NGP\"}"},
{"id":"3","cell":"{\"ruleID\":\"51\",\"description\":\" Ignore all requests for logo sized artwork in NSP ads.\",\"geograph\":\"Yell US\",\"process\":\"Profile Pages\",\"rulesClassification\":\"Logo\",\"types\":\"New\",\"udac\":\"NSP\"}"},
{"id":"4","cell":"{\"ruleID\":\"47\",\"description\":\" Irregular borders are not allowed in banner ads..\",\"geograph\":\"Yell US\",\"process\":\"Profile Pages\",\"rulesClassification\":\"Border\",\"types\":\"New\",\"udac\":\"MRB\"}"}
]}

このグリッド構成で私が犯した間違いは何ですか。私にお知らせください。

4

1 に答える 1

1

あなたの主なエラーはcellas stringの使用だと思います。あなたが持っている

{"id":"1","cell":"{\"ruleID\":\"43\", ...}"},

それ以外の

{"id":"1","cell":{"ruleID":"43", ...}},

2 番目の問題は、非常に奇妙な形式の入力データを使用していることです。一般に、入力データの形式はjsonReaderオプションで指定できます。何も使用しない場合はjsonReader、デフォルト値が使用されます (ドキュメントを参照してください)。したがって、cellプロパティの値は項目の配列でなければなりません:

{"id":"1","cell":["43", ...., "New","NPM"]},

データのすべての行で固定テキストを送信"id"し (特に等しくないダミー値を使用して)、送信する必要性を減らすことができます。データを配列として直接指定できる場合:ruleID"cell"jsonReader: {cell: "", id: 0}

["43", ...., "New","NPM"]

使用法id: 0は、配列の最初の要素が一意のROWIDを指定することを意味します。

jsonReader: {repeatitems: false, id: "ruleID"}または、アイテムを名前付きプロパティを持つオブジェクトとして使用して送信することもできます。

{"ruleID":"43", ....,"types":"New","udac":"NPM"}

したがって、多くの選択肢がありますが、JSON データの現在の形式は決定的に間違っているため、変更する必要があります。

datatype: "json"また、 の代わりに使用した方がよいと思いますdatatype: "jsonstring"。使用する場合は使用datatype: "jsonstring"できますdatastr : result.jSONResponseObject。JSON 文字列であってはdatastrなりません。それはオブジェクトかもしれません。

最後の発言:loadErrorコールバックを使用することをお勧めします。詳細については、回答を参照してください。

于 2012-11-14T07:47:50.037 に答える