数据表正在工作,但在 JS 函数中访问它时收到错误



我实例化了一个数据表,它工作正常。

但是我在 JS 函数中访问它时收到错误。 错误是:

未捕获的类型错误: $(...(。数据表不是函数

我使用的代码是:


$( document ).ready(function() {
    //datatable instantiation
    $('#table-servicos').DataTable({
      "order": [[ 0, "desc" ]]
    });
});
function test() {
  //checkin:1407 Uncaught TypeError: $(...).dataTable is not a function    
  $('#table-servicos').dataTable().order([2, 'desc']).draw();    
}

你的代码是正确的,但有一个错别字。它DataTable不是dataTable.更新代码,它应该按预期工作。这是一个非常疏忽的,每个开发人员都叹息!.

$( document ).ready(function() {
//datatable instantiation
    $('#table-servicos').DataTable({
      "order": [[ 0, "desc" ]]
    });
});
function test() {
  $('#table-servicos').DataTable().order([2, 'desc']).draw();    
}
初始化

表后,您必须在表上使用大写字母 D 的 DataTable。

$('#table-servicos').DataTable().order([2, 'desc']).draw();  

最新更新