我使用可点击行的表格来呈现控制器显示动作, 为了向数据库添加新记录,有一个按钮用于呈现新动作并打开一个弹出式菜单,不需刷新页面,在弹出框中提交表单后动态地将新行添加到数据表中而无需刷新,以前的所有工作都正常,除了新添加的行不可点击以外, 这里是表代码如何使用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)%>”); –