我的home.html.haml页面呈现3个部分:
%h1 Foo
#foo1
= render partial: 'foo/foo', locals: {items: @foo1_items}
#foo2
= render partial: 'foo/foo', locals: {items: @foo2_items}
#foo3
= render partial: 'foo/foo', locals: {items: @foo3_items}
目前,我有一些远程链接可以单独刷新这些部分,向主页发出ajax调用:
= link_to 'refresh', home_path(mode: 'foo1'), remote:true
= link_to 'refresh', home_path(mode: 'foo2'), remote:true
= link_to 'refresh', home_path(mode: 'foo3'), remote:true
我有 home.js.erb ,其中包含以下内容:
<% if params[:mode] == 'foo1'%>
$('#foo1').html('<%= j(render partial: 'foo/foo', locals: {items: @foo1_items}) %>')
<% elsif params[:mode] == 'foo2'%>
$('#foo2').html('<%= j(render partial: 'foo/foo', locals: {items: @foo2_items}) %>')
<% else %>
$('#foo3').html('<%= j(render partial: 'foo/foo', locals: {items: @foo3_items}) %>')
<% end %>
我想知道:
答案 0 :(得分:1)
希望这会有所帮助