我有一个页面可以在按钮按下时来回切换字段。到目前为止,我唯一的解决方案是在原始的 td 中放置一个嵌套的 td,使页面看起来很糟糕。可以在 tds 中看到 tds 的隧道效应:
有没有办法重命名包含的 td 而不是在其中放置一个新的。我每次都必须交换功能,因此有必要重命名它们。这是每个的 js.erb:
删除.js.erb:
<% if @pos_range %>
<% @pos_range.each do |p|%>
$("td#remove_name_<%= p %>").html("<%= escape_javascript(render(:partial => 'some_partial'))%>");
$("td#remove_button_<%= p %>").html("<%= escape_javascript(render(:partial => 'some_partial_2'))%>");
<% end %>
<% else %>
$("td#remove_name_<%= @td_num %>").html("<%= escape_javascript(render(:partial => 'some_partial'))%>");
$("td#remove_button_<%= @td_num %>").html("<%= escape_javascript(render(:partial => 'some_partial_2'))%>");
<% end %>
更新.js.erb:
<% @pos_range.each do |p|%>
$("td#add_device_<%= p %>").html("<%= escape_javascript(render(:partial => 'some_other_partial', :locals => { :id => @id, :position_str => @position_str} ))%>");
$("td#add_device_button_<%= p %>").html("<%= escape_javascript(render(:partial => 'some_other_partial_2', :locals => { :id => @id, :position_str => @position_str} ))%>");
<% end %>
这里是 html.erb 文件:
部分:
<td id=<%="add_device_#{@i.to_s}"%>>
Nothing assigned
</td>
some_partial_2:
<td id=<%="add_device_button_#{@i.to_s}"%>>
<%= link_to "Change", {:controller => :some_controller, :action => :show, :id => @id, :position => @i }, :remote => true, :class => "btn" %>
</td>
some_other_partial:
<td id=<%="remove_name_#{@i.to_s}"%>>
<%= @position_str %>
</td>
some_other_partial_2:
<td id=<%="remove_button_#{@i.to_s}"%>>
<%= link_to "Remove", { :controller => :some_controller, :action => :remove, :id => @id, :position => @i}, :remote => true, :class => "btn btn-danger" %>
</td>