我目前有一个按几个选择框排序的工作表。我最近按照本教程实现了无限/无限滚动:http ://railscasts.com/episodes/114-endless-page-revised?view=asciicast
该教程经过几次更改后工作,但我有一个问题。我在第一列使用计数器,但问题是每次加载下一页时,计数器都会重置为 1,所以计数器就像 1..2..3.. 一直到 50,但是当我滚动到底部时,它会重置为 1。我目前在开始时显示 50 条记录,并且每次用户向下滚动到底部时再显示 50 条记录。我希望下一个记录是 51...52...53...等。然后下次滚动到底部时,从 101 开始,然后是 102...103...104...等等,例如排名列表。
为了获得部分内容,我遵循了本教程,该教程还告诉我如何制作计数器列:http: //xianese.blogspot.com/2008/06/render-collection.html
经过一番研究,我发现我使用的计数器几乎没有记录,并且有几个人报告了它的分页问题,这意味着它不仅仅是无限滚动的问题,而是分页的问题(我正在使用will_paginate)。在一个网站上,一个人说他们已经解决了分页问题,但没有说如何,现在帖子已经关闭,所以我知道有办法解决这个问题。
这是该网站的链接: http ://www.pgrs.net/2007/07/20/render-partial-with-collection-has-hidden-counter/
任何可以帮助我的东西都将不胜感激。
这是我的代码:
文章.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>
谢谢,
杰克