我在Rails应用中使用dataTables。我有一个名为site
的模型。
site
的索引使用dataTable列出网站。
首次加载索引页时
http://localhost:3000/sites
dataTable不起作用。没有控制台错误。
如果我重新加载页面,它就可以了!
在重新加载期间,控制台会显示如下条目:
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/bootstrap.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/bootstrap-editable.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/ColVis.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/datetimepicker.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/datepicker.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/dataTables/bootstrap/3/jquery.dataTables.bootstrap.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:29 -0600
Started GET "/assets/jquery.qtip.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/jquery.treeTable.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/TableTools.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
Started GET "/assets/TableTools_JUI.css?body=1" for 127.0.0.1 at 2014-07-13 17:24:30 -0600
...
感谢您的帮助!
答案 0 :(得分:0)
您使用gem turbolink 吗?如果是,那可能是它的原因,因为它不会重新加载整个页面,只是部分重新加载。您可以通过两种不同的方式解决它:
将您的数据表初始化代码移动到页面:更改, 像application.js中的这样:
$(document).on(" page:change",function(){ $('#yourtable&#39)。dataTable中(); });