2015-10-15 23 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

相关问题