2013-04-17 44 views
2

使用REST API,我從下面的Ajax命令中獲取用於加載數據表的JSON響應。數據表 - 在數據表中加載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響應檢索本身?

回答

1

我通過使用hibernate「org.hibernate.query」查詢結果來改變我的後端,從而得到了答案。從這我能夠獲得記錄列表(一個接一個),並分別加載到網格中。