【发布时间】:2017-04-10 13:59:02
【问题描述】:
我正在为 bootstrap-table 定制一个 ajax 实现(文档:http://bootstrap-table.wenzhixin.net.cn/documentation/):
出于某种原因,我想拥有多个引导表(我们称它们为 searchTable1 、 searchTable2 等)。这些表格中的每一个都将设置在自定义日期范围内(最后 30 天、最后 60 天等)。
我想传递一个参数(如表 Jquery 选择器或任何 data-myCustomDataAttribute 参数)。我怎样才能做到这一点 ? (我尝试使用 call 但引导程序已经在 ajaxCallback 函数上调用了它,所以我似乎不能在这里使用它)。 除了取决于表的两个字段外,制作完全相同的 x 函数看起来很愚蠢。有人有这样做的想法吗?
这是我的代码:
$('#searchTable').bootstrapTable({
columns: [{
field: 'product',
title: 'Produit'
} , {
field: 'language',
title: 'Langue'
}, {
field: 'comment',
title: 'Commentaire'
}],
showRefresh: true,
ajax: provideFeedbacksList,
cache: false,
dataField: 'feedbacks',
totalField: 'total_size',
search: false,
sidePagination: 'server',
pagination: true
});
ajax 提供者:
// I only used this example : http://issues.wenzhixin.net.cn/bootstrap-table/index.html#options/custom-ajax.html
function provideFeedbacksList(params) {
let tableData = params.data;
let serverCall = {};
// add limits and offset provided by bootstrap table
serverCall["page_offset"] = tableData.offset;
serverCall["page_size"] = tableData.limit;
// retrieve the date range for this table :
// will be easy If something like this was possible : params.jquerySelector.attr("date-range-start")
// will be easy If something like this was possible : params.jquerySelector.attr("date-range-end")
let json = JSON.stringify(serverCall);
$.ajax({
url: baseUri + "/feedbacks",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: json,
success: function (reponse) {
params.success(reponse);
},
error: function (er) {
params.error(er);
}
});
}
【问题讨论】:
标签: javascript jquery apply bootstrap-table