Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 然而,使用Datatable格式化表并不能对我所有的表都起作用,只能对一个表起作用_Jquery_Ruby On Rails_Datatable - Fatal编程技术网

Jquery 然而,使用Datatable格式化表并不能对我所有的表都起作用,只能对一个表起作用

Jquery 然而,使用Datatable格式化表并不能对我所有的表都起作用,只能对一个表起作用,jquery,ruby-on-rails,datatable,Jquery,Ruby On Rails,Datatable,我在application.js中有以下内容,我也尝试将其放入prices.coffee.js中 jQuery-> $('#container').dataTable(); 但是,下表不会在DataTable设计中格式化: <h2>Energy Prices</h2> <p id="notice"><%= notice %></p> <table id ="container" class="display"> <

我在application.js中有以下内容,我也尝试将其放入prices.coffee.js中

jQuery->

$('#container').dataTable();
但是,下表不会在DataTable设计中格式化:

<h2>Energy Prices</h2>

<p id="notice"><%= notice %></p>

<table id ="container" class="display">
<thead>
<tr>
    <th>ID</th>
    <th>Month</th>
    <th>Elec</th>
    <th>Gas</th>
    <th>Biomass</th>
</tr>
</thead>
<tbody>
<% @usages.each do |usage| %>
<tr>
    <td><%= usage.price.usage_id %></td>
    <td><%= usage.month.strftime("%b %Y") %></td>
    <% usage.price.attributes.each do |k,v| %>
        <% if v.nil? %>
            <td>N/A</td>
        <% elsif k != "created_at" && k != "updated_at" && k != "month" && k != "id" && k != "usage_id" %>
            <td><%= v %></td>
        <% end %>
    <% end %>
    <td><%= link_to "Edit", edit_price_path(usage) %> </td>
</tr>
<% end %>
</tbody>
</table>
能源价格

身份证件 月 电气 煤气 生物量 不适用
IDs。我想您的问题是有多个表都使用相同的ID。请尝试使用
class
data-*
属性

<table class="container">
$('table.container').dataTable();

$('table.container').dataTable();
或:


$('table[data where=“container”]”)。dataTable();

Hi James感谢您的及时回复。我更改了它,使我的两个表现在都是,并且还将应用程序更改为$('table.container')。dataTable():现在它们都不包含DataTables格式吗?
<table data-whatever="container">
$('table[data-whatever="container"]').dataTable();