t>", oLanguag-6ren">
gpt4 book ai didi

datatables - DataTable().ajax.reload() 未定义

转载 作者:行者123 更新时间:2023-12-03 07:05:39 25 4
gpt4 key购买 nike

我在 DT v1.10 下有以下代码:

var oTable = $('#items')
.dataTable({
sDom: "<'row'<'col-md-4'l><'col-md-6'f>r>t<'row'<'col-md-4'i><'col-md-7'p>>",
oLanguage: {
sLengthMenu: "_MENU_ per page"
},
ajax: "/items",
bProcessing: true,
bServerSide: true,
aoColumnDefs: [
{
aTargets: [-1],
bSearchable: false,
bSortable: false
}
]
})
.on('click', '.btn-danger', function (e) {
if (confirm('Are you sure you want to delete SKU "' + $(this).data('sku') + '"?')) {
$.getJSON($(this).attr('href'), function (data) {
if ('success' in data) {
oTable.ajax.reload(null, false);
}
});
}
event.stopPropagation();
return false;
});

当服务器成功响应时,它会尝试调用行 oTable.ajax.reload(null, false); 但我总是收到错误 Uncaught TypeError: Cannot read property '未定义的重新加载

我在这里做错了什么?

最佳答案

您使用的是旧 API:$().dataTable()(v1.9 及更早版本),该 API 在 DataTables v1.10 中仍然可用。旧的 API 返回 jQuery 对象,因此您应该使用 .api() 才能使用 DataTable API 方法:

oTable.api().ajax.reload();

新的 API 通过以下方式返回:$().DataTable()

Datatables FAQ

Q.: I get an error message stating that an API method is not available
A.: Very likely you are using a jQuery object rather than a DataTables API instance. The form $().dataTable() will return a jQuery object, while $().DataTable() returns a DataTables API instance. Please see the API documentation for further information.

API documentation

It is important to note the difference between $( selector ).DataTable() and $( selector ).dataTable(). The former returns a DataTables API instance, while the latter returns a jQueryJS object. An api() method is added to the jQuery object so you can easily access the API, but the jQuery object can be useful for manipulating the table node, as you would with any other jQuery instance (such as using addClass(), etc.).

关于datatables - DataTable().ajax.reload() 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28313331/

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