[英]Rails will_paginate and ajax append pages
I'm using the will_paginate gem with ajax to append the next page to the bottom of my index every time the user clicks "more" - the problem I'm noticing is that past the second page, clicking more just appends the second page again - what am i missing? 每当用户单击“更多”时,我将使用带有ajax的will_paginate gem将下一页追加到索引的底部-我注意到的问题是在第二页之后,单击更多只是再次将第二页追加-我想念什么?
index.html.erb index.html.erb
<ul class="items" id="event-index">
<%= render 'events' %>
</ul>
<%= will_paginate @events, :previous_label => '', :next_label => 'More', :remote => true %>
index.js.erb index.js.erb
$('#event-index').append('<%= escape_javascript(render("events")) %>');
<% if @events.total_pages == @events.current_page %>
$('.pagination').remove();
<% end %>
<% if @events.current_page %>
$('.ajaxload').hide();
<% end %>
The problem with your setup is that the link that shows the next page doesn't get updated. 设置问题是显示下一页的链接没有更新。 It always shows the second page. 它始终显示第二页。 The simplest solution I can think of is to always delete the pagination and rerender it. 我能想到的最简单的解决方案是始终删除分页并重新呈现它。
$('#event-index').append('<%= escape_javascript(render("events")) %>');
$('.pagination').remove();
<% if @events.next_page %>
$('#event-index').after('<%= will_paginate @events, :previous_label => '', :next_label => 'More', :remote => true %>');
<% end %>
<% if @events.current_page %>
$('.ajaxload').hide();
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.