0
我有一個頁面在按鈕上來回切換字段。到目前爲止,我唯一的解決方案是在原始頁面中嵌入一個td,使頁面看起來很糟糕。你可以看到TDS內TDS的隧道效應:使用js.erb文件重命名td而不是替換它?
有沒有辦法對含有TD命名的,而不是把它裏面一個新的。我必須每次交換功能,所以有必要重新命名它們。下面是每個js.erb:
remove.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 %>
update.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文件:
some_partial:
<td id=<%="add_device_#{@i.to_s}"%>>
Nothing assigned
</td>
some_partia L_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>
感謝@JesseWolgamott,工作perfectely。非常簡單的解決方案,但我很感激它。我是jquery的新手。 –