gpt4 book ai didi

javascript - 如何重新初始化数据表?

转载 作者:太空宇宙 更新时间:2023-11-04 02:17:51 25 4
gpt4 key购买 nike

我有一个带有通知的页面,我想每 10 秒刷新一次,但我不想重新加载整个页面,只是重新加载包含通知的 div。通知本身位于数据表中,该数据表在加载页面时被初始化,但我一直无法让它在重新加载 div 时重新初始化数据表。 div 重新加载正常,但只是一个普通的表。这是我的代码:

$(document).ready(function () {
loadNotificationsTable();
});

setInterval(reloadNotificationsTable, 10000);

function reloadNotificationsTable() {
$('#NotificationsTable').dataTable().fnDestroy();

$("#notificationsPlaceholder").load(location.href + " #notificationsPlaceholder>*", "");

$("#notificationsPlaceholder").ready(function () {

loadNotificationsTable();
});
};

function loadNotificationsTable() {
$('#NotificationsTable').dataTable({
ajax: "data.json",
"bLengthChange": false,
'iDisplayLength': 1000,
"bSort": false,
"bFilter": false,
"sDom": 'ft<"bottom"ilp>',
"bDestroy": false,
"bPaginate": false,
"bInfo":false
});
};

有人能帮助我并告诉我我做错了什么吗?

最佳答案

在回调中加载完成后尝试重新初始化数据表:

$("#notificationsPlaceholder").load(location.href + " #notificationsPlaceholder>*",function(data){
loadNotificationsTable();
});

同时将此添加到您的初始化代码中因为你想更换 table

https://legacy.datatables.net/ref#bDestroy

"bDestroy": true,

关于javascript - 如何重新初始化数据表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38634210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com