2

使用 REST API,我从下面的 Ajax 命中获取 JSON 响应以加载数据表。

我收到错误:Uncaught TypeError: Cannot read property 'length' of undefined.

$('#example').dataTable({
    "bSort" : false,
    "bDestroy" : true,
    "sPaginationType" : "full_numbers",
    "bProcessing" : false,
    "bFilter" : true,
    "bServerSide" : true,
    "bAutoWidth" : false,
    "sAjaxSource" : 'exampledatagrid.json?token=' + sessionId,
    "aoColumns" : [{
        "mData" : "0",
        "mData" : "1",
        "mData" : "2",
        "mData" : "3"
    }],
    "fnServerParams" : function(aoData) {
        alert(aoData);
        aoData.push({
            "name" : "colNameMode",
            "value" : "userStatusList"
        }, {
            "name" : "colName_0",
            "value" : "userIDList"
        }, {
            "name" : "colName_1",
            "value" : "userNameList"
        }, {
            "name" : "colName_2",
            "value" : "userRemarksList"
        });
    },
    "fnRowCallback" : function(nRow, aData, iDisplayIndex) {
        alert(aData);
    },
    "fnDrawCallback" : function(oSettings) {
        if ( oSettings.bSorted || oSettings.bFiltered ) {
            for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ ) {
                $('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
            }
        }
    }
});

JSON响应是:

{"userRemarksList":["TECHNOLOGY","GUEST","HOUSE","SECURITY"],"userIDList":[23,45,23,54],"userNameList":["Michael","Danny","Rahil","Ramesh"],"userStatusList":[0,0,1,1]} 

我想知道我是否必须更改我的 JSON 格式,或者我是否可以从上述 JSON 响应本身中检索?

4

1 回答 1

1

我通过使用hibernate“org.hibernate.query”查询结果来改变我的后端得到了答案。由此我能够获得记录列表(一个接一个)并将其分别加载到网格中。

于 2013-05-07T11:41:40.270 回答