问题描述
我有一个JS模块中定义的JQuery数据表.而且,在其他地方,我试图借助Datatable的ID选择器重新加载它.在这里,我想传递我遇到麻烦的新请求发布数据.
I have a JQuery Datatable that is defined in a JS Module. And, elsewhere, I'm trying to reload it with the help of Datatable's ID selector. Here, I want to pass in new request post data which I'm having trouble with.
我的尝试:
在模块A中:
$(selectors.Datatable)
.DataTable({
bProcessing: true,
serverSide: true,
ajax: {
data: initialPostData,
url: urls.read,
method: 'POST'
},
columns: [...],
autoWidth: false,
searchDelay: 500
});
在模块B中:
var newPostData = [...];
var dataTableWidget = $(selectors.datatableSelector).DataTable();
dataTableWidget.ajax.params(newPostData);
dataTableWidget.ajax.reload();
我期望 dataTableWidget.ajax.params(newPostData);
应该在ajax请求中发布新数据.但这不是.
I was expecting dataTableWidget.ajax.params(newPostData);
should be post new data in the ajax request. But it isn't.
params
不会在这里提供帮助.来自文档:
params
is not the one that is going to help here. From documentation:
推荐答案
研究了JQuery Datatable的文档后,我发现这是一种解决方法.
After looking into the documentation of JQuery Datatable, I found this as a workaround.
dataTableWidget.settings()[0].ajax.data = newPostData;
dataTableWidget.ajax.reload();
这篇关于jQuery数据表:更新请求/关于数据表重载的PostData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!