我有一个配置了数据表的rails 5.2项目。该插件工作正常但如果我更改页面然后点击后退按钮,表中的数据不会再次加载数据表。它说“表格中没有数据”。这对我来说听起来像是一个涡轮问题。
我使用以下来生成表:
$( document ).on('turbolinks:load', function() {
$("#prjtbl").dataTable();
});
datatables插件在页面更改之间加载,但表中的数据不会刷新。有想法该怎么解决这个吗?
更新:Application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require jquery
//= require datatables
//= require popper
//= require bootstrap-sprockets
//= require shards-dashboards
//= require trix
//= require activestorage
//= require turbolinks
//= require_tree .
Page.js
JQuery(function() {
$( document ).on('turbolinks:load', function() {
$("#prjtbl").dataTable();
});
});
document.addEventListener("turbolinks:load", function() {
"use strict";
if ($("#prjtbl").length == 0) {
$("#prjtbl").dataTable();
}
})