我不知道我在這裏失蹤。我在頁面上實現了無限滾動,但結果不止一次重複。我爲我的開發環境創建了一系列依次製作的項目。他們正在無限的滾動重複例如。項目沒有49,48,47,46,45,44,46,45,44,46,45,44,43,......導軌無限滾動重複內容
index.js.erb的
$('#my-posts').append('<%= j render @news %>');
<% if @news.next_page %>
$('.pagination').replaceWith('<%= j will_paginate @news %>');
<% else %>
$(window).off('scroll');
$('.pagination').remove();
<% end %>
索引.html.erb
<section class='page-content-container'>
<h2 class='static-page-subheading'>Stay Up to Date</h2>
<%= render 'news' %>
<div id="infinite-scrolling">
<%= will_paginate @news%>
</div>
</section>
_news.html.erb
<div id='my-posts'>
<% @news.each do |news| %>
<div class='news-item-container'>
<h2><%= news.title %></h2>
<h3><%= news.created_at %></h3>
<%= truncate(news.body, :length => 500, escape: false) %>
<%= link_to 'Read More', news %>
<div class="addthis_sharing_toolbox"></div>
</div>
<% end %>
</div>
pagination.js.coffee (這裏忽略縮進)
jQuery ->
if $('#infinite-scrolling').size() > 0
$(window).on 'scroll', ->
more_news_url = $('.pagination .next_page a').attr('href')
if more_news_url && $(window).scrollTop() > $(document).height() - $(window).height() - 60
$('.pagination').html('<img src="/assets/ajax-loader.gif" alt="Loading..." title="Loading..." />')
$.getScript more_news_url
return
return
不,它只是堆棧溢出。掛上我會編輯 –
我可以看到你的控制器嗎? –