我正在尝试在 Rails 应用程序中运行数据表,但是这对我来说不起作用。
在我的宝石文件中:
gem 'jquery-datatables-rails'
gem 'jquery-rails'
gem 'bootstrap-sass'
用于检查状态的命令行管理程序命令:
gem list | grep -i datatables
jquery-datatables-rails (1.12.2)
应用.css:
*= require dataTables/jquery.dataTables
应用.js
//= require dataTables/jquery.dataTables
客户端.js
jQuery ->
$('#clients').dataTable()
应该正确初始化数据表吗?
Firebug 错误:
TypeError: $(...).dataTable is not a function
$('#clients').dataTable();
或:
ReferenceError: jQuery is not defined
$('#clients').dataTable({
有什么想法吗?谢谢你的时间。
我最近有类似的错误消息。首先,您是否在表标签中设置了 id?您的表格中有头和头标签吗?
<table id='clients'>
<thead>
<tr>
<th>...</th>
</tr>
</thead>
<tbody>
<% @clients.each do |client| %>
<tr>
<td>...</td>
</tr>
</tbody>
</table>
第二:您正在使用->
符号,即 CoffeeScript 替换函数关键字,此外 CoffeeScript 对选项卡敏感。确保您的 CoffeeScript 文件名以 .coffee
结尾。我会尝试使用选项卡并更改文件名。
客户.js.咖啡
jQuery ->
$('#clients').dataTable()
也许通过这些更改,您将以数据表的工作结束。