2015-10-15 21 views
0

我有下面的代碼在我的spring mvc項目中生成jquery數據表。 但我加載的頁面,JavaScript拋出一些警告。 enter image description here請求jQuery數據表中第0行的未知參數1

var sTable = $('#tblKeyDetails').dataTable({ 
      "aoColumns" : [ null,null, null,null], 
      "sPaginationType" : "full_numbers", 
     }); 
    $.ajax({ 
      dataType : 'json', 
      type : 'GET', 
      url : 'getKeyDetails.html', 
      data :({ 
       form : $('#ddlKeyStatus').val() 
      }), 
      beforeSend : function() { 
       //startPreloader(); 
      }, 
      complete : function() { 
       //stopPreloader(); 
      }, 
      success : function(data) { 
       sTable.fnClearTable(); 
        $.each(data, function(index,item) { 
        var rowCount = index+1; 
     sTable.fnAddData([ '<label align="center">'+rowCount+'</label>', 
             item['key'], 
             item['date'], 
             item['userEmail'] 
             ]); 
        }); 

      } 
     }); 

響應對象包含

date: null 
deviceId: null 
id: 3 
key: "DQAIYLFFDVFG" 
userEmail: null 
userId: 0 
+1

當您的表格配置爲3時,您將重新添加一個包含4列的行 – Vanojx1

+0

您是否檢查了警告中給出的鏈接?這將解決問題;) – Andreas

+0

但沒有找到任何解決方案。 – boycod3

回答

1

改變這一點:

sTable.fnAddData([ '<label align="center">'+rowCount+'</label>', 
             item['key'], 
             item['date'], 
             item['userEmail'] 
             ]); 

sTable.fnAddData([ '<label align="center">'+rowCount+'</label>', 
             item['key']!=null ? item['key'] : "", 
             item['date']!=null ? item['date'] : "", 
             item['userEmail']!=null ? item['userEmail'] : "" 
             ]); 

防止空值將解決您的問題。您也可以禁用datables警告消息,但修復問題可能會更好。

+0

變種穩定= $( '#tblKeyDetails')的dataTable({ \t \t 「aoColumns」:[NULL,NULL,NULL,NULL,{ 「defaultContent」: 「」}], \t \t 「sPaginationType」:「full_numbers 「, \t}); – boycod3

+0

哦,這是一個其他好方法,以防止警告:) – Vanojx1

+1

是啊,無論如何謝謝 – boycod3

相關問題