2014-01-19 32 views
1

嘗試使用jQuery的數據表,使用基金會4數據表在Rails中使用基金會:不能調用方法「FNINIT」的未定義

每github上安裝說明一個Rails 4.0.2項目,安裝

gem 'jquery-datatables-rails', '1.12.2' 

添加所需的線我的application.js

//= require jquery 
//= require jquery-ui 
//= require jquery_ujs 
//= require jquery.remotipart 
//= require foundation 
//= require select2 
//= require jquery.Jcrop 
//= require dataTables/jquery.dataTables 
//= require dataTables/jquery.dataTables.foundation 

...和application.css

簡要

<table class="datatable"> 
    <thead> 
<tr> 
    <th>Animal</th> 
    <th>Species</th> 
    <th>Breed</th> 
</tr> 
</thead> 
<tbody> 
    <% @animals.each do |animal| %> 
    <tr> 
      <td><%= animal.name %></td> 
     <td><%= animal.species %></td> 
     <td><%= animal.breed %></td> 
    </tr> 
    <% end %> 
    </tbody> 
</table> 

表閃爍爲未格式化的內容,然後消失:

*= require_self 
*= require foundation_and_overrides 
*= require select2 
*= require jquery-ui.min 
*= require jquery-ui-1.10.3.custom 
*= require jquery.Jcrop 
*= require dataTables/jquery.dataTables.foundation 

這添加到我的application.js文件:

$(function(){ 
    .... 
    $('.datatable').dataTable({ 
    "sPaginationType": "foundation" 
    }); 
}); 

在我html.erb文件。檢查Chrome資源中的瀏覽器錯誤是「Uncaught TypeError:無法調用未定義的方法'fnInit'」。

+0

看起來是不會被裝載的基礎刪除此列。確保它已加載並且它是最新版本 - > https://github.com/DataTables/Plugins/blob/master/integration/foundation/dataTables.foundation.js – davidkonrad

+0

根據每個dk的評論,我獲得了最新的dataTables。通過https://github.com/DataTables/Plugins/blob/master/integration/foundation/dataTables.foundation.js foundation.js和解決我的問題。 – user1183366

回答

0

從application.js中

//= require jquery 
//= require jquery_ujs 
//= require foundation 
//= require turbolinks 
//= require_tree . 
相關問題