获取 DataTables 警告:非表节点初始化 (TBODY) 错误

我仍然无法找到错误处理它 1 小时。我收到 DataTables 警告:

非表节点初始化(TBODY)。有关此错误的更多信息,请参阅http://datatables.net/tn/2

我不知道为什么。我一遍又一遍地检查我的代码,我的后颈疼痛。

http://img.mukewang.com/6129f21a00013ff207250286.jpg

<table class="table table-bordered table-sm table-hover datatable dt-responsive nowrap">

  <thead>

    <tr>

      <th>Category</th>

      <th>Action</th>

    </tr>

  </thead>

  <tbody id="category_data"></tbody>

</table>

show_categories(); //call function show all category


$('#category_data').dataTable();


//function show all category

function show_categories() {

  $.ajax({

    type: 'ajax',

    url: base_url + 'Admin/Categories/fetch_categories',

    async: true,

    dataType: 'json',

    success: function(data) {

      var html = '';

      var i;

      for (i = 0; i < data.length; i++) {

        html += '<tr>' +

          '<td>' + data[i].category + '</td>' +

          '<td style="text-align:right;">' +

          '<button type="button" class="btn btn-xs btn-info" data-category_id="' + data[i].category + '"><em class="fas fa-edit"></em></button> ' +

          '<button type="button" class="btn btn-xs btn-danger" data-category_id="' + data[i].category + '"><em class="fas fa-trash"></em></button>' +

          '</td>' +

          '</tr>';

      }

      $('#category_data').html(html);

    }

  });

}


明月笑刀无情
浏览 264回答 2
2回答

慕妹3242003

我的代码中有这个错误;当已经初始化所选节点的DataTable实例时,通过将选项传递给Dataatables构造函数对象来触发。你应该使用像:$('#example').dataTable( {paging: false} );在您的代码中只有 1 次。

阿晨1998

function show_categories(){&nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type&nbsp; : 'ajax',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: base_url + 'Admin/Categories/fetch_categories',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; async : true,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataType : 'json',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success : function(data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var html = '';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var i;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i < data.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html += '<tr>' +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<td>' + data[i].category + '</td>' +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<td style="width:80px;">' +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<button type="button" class="btn btn-xs btn-info" data-category_id="' + data[i].category +'"><em class="fas fa-edit"></em></button> '+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<button type="button" class="btn btn-xs btn-danger" data-category_id="' + data[i].category +'"><em class="fas fa-trash"></em></button>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</td>' +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</tr>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('#category_showData').html(html);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }<table id="category_dataTables" class="table table-bordered table-sm table-hover datatable dt-responsive nowrap">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Category</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Action</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tbody id="category_showData">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tbody>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </table>
打开App,查看更多内容
随时随地看视频慕课网APP