日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

DataTables中提示:DataTables warning: table id=example - Cannot reinitialise DataTable.

發布時間:2025/3/19 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DataTables中提示:DataTables warning: table id=example - Cannot reinitialise DataTable. 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

在頁面中有一個下拉框select,在select的change事件中,每此要根據選擇的值的

不同進而在dataTables中顯示不一樣的值。

錯誤提示如圖:

錯誤代碼如下:

$(document).ready(function() {//選擇退貨方后退貨目的地綁定聯動$("#businessInitiator").bind("change", function () {//獲取選中的option的value值var selected = $("#businessInitiator option:selected").val();//獲取退貨目的地Input對象var destination = $("#destination");switch (selected){case '原料立庫':destination.val("原料立庫退貨點")break;case '清潔車間':destination.val("清潔車間退貨點")break;case '正極車間':destination.val("正極車間退貨點")break;case '負極車間':destination.val("負極車間退貨點")break;default:destination.val("其它退貨點")}//退貨目的地聯動完成// DataTable初始化var t = $('#example').DataTable({"language": {"processing": "處理中...","lengthMenu": "顯示 _MENU_ 項結果","zeroRecords": "沒有匹配結果","info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項","infoEmpty": "顯示第 0 至 0 項結果,共 0 項","infoFiltered": "(由 _MAX_ 項結果過濾)","infoPostFix": "","search": "搜索:","searchPlaceholder": "搜索...","url": "","emptyTable": "表中數據為空","loadingRecords": "載入中...","infoThousands": ",","paginate": {"first": "首頁","previous": "上頁","next": "下頁","last": "末頁"},"aria": {paginate: {first: '首頁',previous: '上頁',next: '下頁',last: '末頁'},"sortAscending": ": 以升序排列此列","sortDescending": ": 以降序排列此列"},"decimal": "-","thousands": "."},"processing": true,"searching" : false,"pageLength": 100,"serverSide": true,"columnDefs": [ {"searchable": false,"orderable": false,"targets": "_all",}],"dom": '<"top">rt<"bottom"flpi><"clear">',columns: [{ data: 'id' ,"orderable" : false},{ data: 'goodsLocationNumber' },{ data: 'locationTypeName' ,"orderable" : false},{ data: 'saveMaterialTypeName' ,"orderable" : false},{ data: 'materielStatusName',"orderable" : false},{ data: 'shelveName' ,"orderable" : false},{ data: 'remark',"orderable" : false }],columnDefs: [{//?? 指定第1列,從0開始,0表示第一列,1表示第二列……"targets": 0,"bSortable": false,"render": function(data, type, row, meta) {if (row.isSelected == 1){return '<input type="checkbox" class="checkchild" onclick="childClick(this)" checked="checked" value="' + row.id + '" />'}return '<input type="checkbox" class="checkchild" onclick="childClick(this)" value="' + row.id + '" />'}}],"ajax": function (data, callback, setting) {data.editActionId = $("#refundOrderId").val();$.ajax({type: 'POST',url: "/busGoodsLocation/getRejectsLocationsList",cache: false,? //禁用緩存//async: true,data: JSON.stringify(data),? //傳入組裝的參數contentType: "application/json",dataType: "json",success: function (result) {callback(result);}})}});}); });

實現

根據錯誤提示是不能初始化dataTable,即在同一個頁面中不能多次初始化DataTables。

解決,在每此的點擊事件中初始化之前先還原初始化。

?$("#example").dataTable().fnDestroy();//還原初始化了datatable

完整示例代碼:

$(document).ready(function() {//選擇退貨方后退貨目的地綁定聯動$("#businessInitiator").bind("change", function () {//獲取選中的option的value值var selected = $("#businessInitiator option:selected").val();//獲取退貨目的地Input對象var destination = $("#destination");switch (selected){case '原料立庫':destination.val("原料立庫退貨點")break;case '清潔車間':destination.val("清潔車間退貨點")break;case '正極車間':destination.val("正極車間退貨點")break;case '負極車間':destination.val("負極車間退貨點")break;default:destination.val("其它退貨點")}//退貨目的地聯動完成$("#example").dataTable().fnDestroy();//還原初始化了datatable// DataTable初始化var t = $('#example').DataTable({"language": {"processing": "處理中...","lengthMenu": "顯示 _MENU_ 項結果","zeroRecords": "沒有匹配結果","info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項","infoEmpty": "顯示第 0 至 0 項結果,共 0 項","infoFiltered": "(由 _MAX_ 項結果過濾)","infoPostFix": "","search": "搜索:","searchPlaceholder": "搜索...","url": "","emptyTable": "表中數據為空","loadingRecords": "載入中...","infoThousands": ",","paginate": {"first": "首頁","previous": "上頁","next": "下頁","last": "末頁"},"aria": {paginate: {first: '首頁',previous: '上頁',next: '下頁',last: '末頁'},"sortAscending": ": 以升序排列此列","sortDescending": ": 以降序排列此列"},"decimal": "-","thousands": "."},"processing": true,"searching" : false,"pageLength": 100,"serverSide": true,"columnDefs": [ {"searchable": false,"orderable": false,"targets": "_all",}],"dom": '<"top">rt<"bottom"flpi><"clear">',columns: [{ data: 'id' ,"orderable" : false},{ data: 'goodsLocationNumber' },{ data: 'locationTypeName' ,"orderable" : false},{ data: 'saveMaterialTypeName' ,"orderable" : false},{ data: 'materielStatusName',"orderable" : false},{ data: 'shelveName' ,"orderable" : false},{ data: 'remark',"orderable" : false }],columnDefs: [{//?? 指定第1列,從0開始,0表示第一列,1表示第二列……"targets": 0,"bSortable": false,"render": function(data, type, row, meta) {if (row.isSelected == 1){return '<input type="checkbox" class="checkchild" onclick="childClick(this)" checked="checked" value="' + row.id + '" />'}return '<input type="checkbox" class="checkchild" onclick="childClick(this)" value="' + row.id + '" />'}}],"ajax": function (data, callback, setting) {data.editActionId = $("#refundOrderId").val();$.ajax({type: 'POST',url: "/busGoodsLocation/getRejectsLocationsList",cache: false,? //禁用緩存//async: true,data: JSON.stringify(data),? //傳入組裝的參數contentType: "application/json",dataType: "json",success: function (result) {callback(result);}})}});}); });

?

總結

以上是生活随笔為你收集整理的DataTables中提示:DataTables warning: table id=example - Cannot reinitialise DataTable.的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。