我使用可點擊行的表格來呈現控制器顯示動作, 爲了向數據庫添加新記錄,有一個按鈕用於呈現新動作並打開一個彈出式菜單,不需刷新頁面,在彈出框中提交表單後動態地將新行添加到數據表中而無需刷新,以前的所有工作都正常,除了新添加的行不可點擊以外, 這裏是表代碼如何使用js將數據鏈接動態添加到數據錶行
<%- model_class = Supplier -%>
<table class="table table-custom pointer" id="editable-usage">
<thead>
<tr>
<th class="table-text-center"><%= model_class.human_attribute_name(:name) %></th>
<th class="table-text-center"><%= model_class.human_attribute_name(:code) %></th>
<th class="table-text-center"><%= model_class.human_attribute_name(:email) %></th>
<th class="table-text-center"><%= model_class.human_attribute_name(:total_credit) %></th>
<th class="table-text-center"><%= model_class.human_attribute_name(:notes) %></th>
</tr>
</thead>
<tbody>
<% @suppliers.each do |supplier| %>
<tr data-link="<%= supplier_path(supplier) %>">
<td><%= supplier.name %></td>
<td><%= supplier.id %></td>
<td><%= supplier.email %></td>
<td><%= supplier.total_credit %></td>
<td><%= supplier.notes %></td>
</tr>
<% end %>
</tbody>
</table>
create.js.erb文件代碼:
// hide the popup
$('#splash').modal('hide');
// insert the new row
var t = $('#editable-usage').DataTable();
t.row.add([ '<%= @supplier.name %>','SC00<%[email protected] %>','<%[email protected] %>','','<%[email protected] %>']).draw();
如何添加(數據鏈路= 「<%= supplier_path(供應商)%>」)這一新潮流
其不工作我試過var t = $('#editable-usage')。DataTable(); t.row.add(['<%= @ supplier.name%>','SC00 <%= @ supplier.id%>','<%= @ supplier.email%>','','< %(@supplier.notes%>'])。draw(); t.row.data(「link」,「<%= supplier_path(@ supplier.id)%>」); –