0

この問題に対して与えられた解決策を試しました。しかし、それでもうまくいきません。JSON レスポンスの形式が正しくないように感じます。

struts2 に JQGrid を実装しました。アクションでユーザー リストを作成し、struts.xml で結果の型を json として使用して、json 型として返します。

これは私が取得したJsonです。

{"JSON":"success","userList":[{"fName":"abi","lName":"babu"},{"fName":"abi1","lName":"babu1"},{"fName":"abi2","lName":"babu2"},{"fName":"abi3","lName":"babu3"},{"fName":"abi4","lName":"babu4"},{"fName":"abi5","lName":"babu5"},{"fName":"abi6","lName":"babu6"}]}

JSPページは、

 <script type="text/javascript">
    $(function () {
        'use strict';
        $("#datagrid").jqGrid({
            url: "json-table",
            datatype: "json",
            colNames:['fName','lName'],
            colModel:[
                {name:'fName',index:'fName', key:true, width:100,editable:true,editoptions:{size:10}},
                {name:'lName',index:'lName', width:100,editable:true},
            ],
            rowNum:10,
            rowList:[3,6],
            loadonce: true,
            pager: '#navGrid',
            sortname: 'fName',
            sortorder: "asc", 
            height: "auto", //210,
            width:600,
            onSelectRow: function(id) {
                var getID = $(this).jqGrid('getCell', id, 'fName');
            },
            viewrecords: true,
            caption:"JQ GRID"
        });
    });
</script>

どんな助けでも大歓迎です。ありがとう。

4

1 に答える 1

0

jsonReader入力データの形式に対応するパラメーターを含める必要があります。

jsonReader: {root: "userList", repeatitems: false}

デモをご覧ください。

于 2012-11-06T06:16:58.513 に答える