简体   繁体   English

Jquery table.destroy 在第一次着火点击时不起作用

[英]Jquery table.destroy doesn't work the first time on fire click

HTML code: HTML 代码:

<!-- Devices List Navbar Menu -->
<li class="nav-item">
<a href="#" class="navbar-nav-link" id="deviceSearch"><i class="icon-search4 pr-1"></i> Devices</a>
</li>  <!-- END Devices List Navbar Menu -->

Javascript code: Javascript 代码:

$(document).ready( function () {
    var alarmTable = $('#alarm_datatable').DataTable({
        //do staff
    });

    $("#deviceSearch").click(function(){
        alarmTable.destroy();
    });
}); 

The problem is that the table is destroyed only after the second click of the link with id "deviceSearch".问题是该表仅在第二次单击 ID 为“deviceSearch”的链接后才被销毁。 The behavior is the same whether the click function is in or out of $(document).ready无论点击 function 是否在$(document).ready中,行为都是相同的

At the first click the table header disappears, and at the second click the datatable disappears.第一次单击表 header 消失,第二次单击数据表消失。

Could you help me why this happens and how to solve it?你能帮我为什么会发生这种情况以及如何解决它吗?

you have to precise true to remove completely the datatable:您必须精确到true才能完全删除数据表:

$("#deviceSearch").click(function(){
    alarmTable.destroy(true);
});

Completely remove the table from the DOM (true) or leave it in the DOM in its original plain un-enhanced HTML state (default, false).从 DOM 中完全删除表(true)或将其保留在 DOM 中的原始普通未增强 HTML state(默认值,false)中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM