【问题标题】:rails datatables TypeError导轨数据表类型错误
【发布时间】:2014-01-15 04:52:02
【问题描述】:

我正在尝试在 Rails 应用程序中运行数据表,但是 它不适合我。

在我的 Gemfile 中:

gem 'jquery-datatables-rails'
gem 'jquery-rails'
gem 'bootstrap-sass'

Shell 命令检查存在性:

gem list | grep -i datatables

jquery-datatables-rails (1.12.2)

application.css:

*= require dataTables/jquery.dataTables

应用程序.js

//= require dataTables/jquery.dataTables

clients.js

jQuery ->
$('#clients').dataTable()

应该初始化数据表吗?

Firebug 错误:

TypeError: $(...).dataTable is not a function


$('#clients').dataTable();

或:

ReferenceError: jQuery is not defined


$('#clients').dataTable({

有什么想法吗?感谢您的宝贵时间。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 jquery-datatables


    【解决方案1】:

    我最近收到了类似的错误消息。首先,您是否在表格标签中设置了id?你的表中有thead 和tbody 标签吗?

    <table id='clients'>
    <thead>
      <tr>
        <th>...</th>
      </tr>
    </thead>
    <tbody>
    <% @clients.each do |client| %>
      <tr>
        <td>...</td>
      </tr>
    </tbody>
    </table>
    

    第二:你正在使用-&gt; 符号,即CoffeeScript 替换function 关键字,此外CoffeeScript 是制表符敏感的。确保您的 CoffeeScript 文件名以 .coffee 结尾。我会尝试使用选项卡并更改文件名。

    clients.js.coffee

    jQuery ->
      $('#clients').dataTable()
    

    也许通过这些更改,您的 DataTable 可以正常工作。

    【讨论】:

      猜你喜欢
      • 2020-04-09
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-04
      相关资源
      最近更新 更多