我使用 jquery 数据表来显示我从 jsonresponse 获得的数据。表格的初始显示还可以,但是当我点击刷新并使用时
$('#search-notable-authors').DataTable().destroy();
$('#search-notable-authors').DataTable(
它会重新加载表格,但会按照我点击刷新按钮的次数重复标题图标。
这是完整的jq代码
<script type="text/javascript">
var $jquery_1_11_3 = jQuery.noConflict(true);
(function ($) {
$(document).ready(function () {
$("#refresh-btn").on("click",function(){
showItemsTable1();
});
ajaxPaths = {
allNotableAuthors: "{{ path('json_getAllNotableAuthors') }}",
allNotableAuthorsByJournal: "{{ path('json_getAllNotableAuthorsByJournal') }}"
},
itemsTable = null,
getItems = function () {
return $.Deferred(function () {
var that = this;
$.ajax({
type: "POST",
data: $('#articlesList').serialize(),
url: ajaxPaths.allNotableAuthors,
success: function (data) {
console.log(data);
that.resolve(data);
}
});
});
},
getItems1 = function () {
return $.Deferred(function () {
var that = this;
var journal = $("#search_authors_name_short").val();
$.ajax({
type: "POST",
data: { term : journal },
url: ajaxPaths.allNotableAuthorsByJournal,
success: function (data) {
console.log(data);
that.resolve(data);
}
});
});
},
showItemsTable = function () {
return $.Deferred(function () {
var that = this;
getItems().done(function (itemsData) {
$('#search-notable-authors').DataTable({
aLengthMenu: [
[25, 50, 100, 200, -1],
[25, 50, 100, 200, "All"]
],
iDisplayLength: -1,
data: itemsData,
columns: [
{"data": 0},
{"data": 1},
{"data": 2},
{"data": 3},
{"data": 4}
]
});
that.resolve();
});
});
},
showItemsTable1 = function () {
return $.Deferred(function () {
var that = this;
getItems1().done(function (itemsData) {
$('#search-notable-authors').DataTable().destroy();
$('#search-notable-authors').DataTable({
aLengthMenu: [
[25, 50, 100, 200, -1],
[25, 50, 100, 200, "All"]
],
iDisplayLength: -1,
data: itemsData,
columns: [
{"data": 0},
{"data": 1},
{"data": 2},
{"data": 3},
{"data": 4}
]
});
that.resolve();
});
});
}
showItemsTable();
});//end of doc ready
})($jquery_1_11_3);
</script>
如何在不复制标题图标的情况下解决此问题?