4

我正在使用twitter引導和will_paginate,並且我有一張表,我想實現無限滾動。Rails無盡頁面/無限滾動

該表格是固定長度並已經滾動。我最近跟着Railscasts Episode#114的修訂版本,但它不適合我。當我滾動到表格底部時,它表示獲取更多文章,但實際上並沒有獲取更多文章。

這裏是我的代碼:

Articles.js.coffee:

jQuery -> 
    if $('.pagination').length 
      $(articles).scroll -> 
        url = $('.pagination .next_page').attr('href') 
        if url && $(articles).scrollTop() > $(document).height() -    
        $(articles).height() + 585 
         $('.pagination').text('Fetching more players...') 
         $.getScript(url) 
$(articles).scroll() 

index.js.erb的:

$('#articles').append('<%= j render(@articles) %>'); 
<% if @articles.next_page %> 
    $('.pagination').replaceWith('<%= j will_paginate(@articles) %>'); 
<% else %> 
    $('.pagination').remove(); 
<% end %> 

我的控制器和桌子都稱爲文章。我不知道它是不是工作,因爲它是一個表與整個頁面。

如果我需要發佈更多文件,請讓我知道。

+1

爲了將來的參考,請不要雙重發布問題,如果您有其他詳細信息可以幫助我們回答您的問題,請編輯原始問題。 – Noz

+0

打開Firebug,你看到有什麼JS錯誤嗎? –

+0

[Rails Infinite Scroll/Endless Page Table with will \ _paginate]可能重複(http://stackoverflow.com/questions/12994866/rails-infinite-scroll-endless-page-table-with-will-paginate) –

回答

3

我想通過遵循railscasts第114集,但我不得不做一些改變,以使其工作。

這是我的新代碼:

articles.js.coffee

jQuery -> 
    if $('.pagination').length 
     $('#articles_table').scroll -> 
       url = $('.pagination .next_page').attr('href')   
       if url && $('#articles_table')[0].scrollHeight -  
       $('#articles_table').scrollTop() < 700     
         $('.pagination').text('Fetching more users...') 
         $.getScript(url) 
$('#articles_table').scroll() 

index.html.erb

<table class="table table-striped table-bordered span8 table-condensed"  
id="articles_table" > 
<thead class="header"> 
    <tr> 
     <th>ID</th> 
     <th>Title</th> 
     <th>Description</th> 
     <th>Created_At</th> 
    </tr> 
</thead> 
<tbody> 
<%= render @articles %> 

</tbody> 

index.js.erb的

$('#articles_table').append('<%= j render(@articles) %>'); 
<% if @articles.next_page %> 
$('.pagination').replaceWith('<%= j will_paginate(@articles) %>'); 
<% else %> 
$('.pagination').remove(); 
<% end %> 

_article.html.erb

<tr> 
     <td> <%= article_counter +1 %> </td> 
     <td> <%= article.Title %> </td> 
     <td> <%= article.Description %> </td> 
     <td> <%= article.Created_At %> </td> 
</tr> 

我不得不圍繞JavaScript的改變一點點,使其爲我工作,然後創建一個部分。 javascript的變化是因爲我使用的是固定長度的表格而不是整個頁面。