Ruby-Rails 3-AJAXinate分页和排序 [英] Ruby - Rails 3 - AJAXinate Paginate and sorting
问题描述
过去6个小时,我一直在努力进行这项工作.我尝试了几个代码示例,但它们似乎都不起作用.我读到will_paginate不是为rails 3设计的.我知道它可以进行分页但不能发出ajax请求.尝试使用JQuery来解决该Ajax问题,但那里也没有运气.这很奇怪,没有花太多精力去做一件小事.分页正在发生,但必须进行ajax调用.在发疯之前,我真的需要在这里提供一些好的建议.
Last 6 hours I am trying to get this working. I tried several code examples but none of them seem to work. I read will_paginate is not designed for rails 3. I got it working to a point where it does pagination but cannot make ajax requests. Tried JQuery to help that ajax problem , no luck there too. This is odd, doesn't take this much try to a small thing working. Pagination is happening but it has to make an ajax call. I really need some good advice here before I go crazy.
查看-
<div id="digg_pagination">
<div class="page_info">
<%= page_entries_info @list_page %>
</div>
<%= will_paginate(@list_page , :container => true, :remote => true, :page_links => true ) %>
</div>
生成HTML-
<div id="digg_pagination">
<div class="page_info">
Displaying Item<b>2 - 2</b> of <b>2</b> in total
</div>
<div class="pagination" remote="true">
<a class="previous_page" rel="prev start" href="/item/item_list?page=1">← Previous</a>
<a rel="prev start" href="/item/item_list?page=1">1</a>
<em class="current">2</em> <span class="next_page disabled">Next →</span>
</div>
</div>
JS-
$(function(){
$('#item_list').html(<%= (render :partial => 'item_list').to_json.html_safe %>);
$('.pagination a').attr('data-remote', 'true'); # Doesn't add the html attribute
$('.pagination a').livequery('click', function() {
$.getScript(this.href);
return false;
});
}); #Tried bind 'click', live, livequery. none worked.
推荐答案
这对我有用:
# in a generic js
$(document).ready(function () {
$(".pagination").find("a").livequery(function () {
$(this).attr("data-remote", true);
});
});
will_paginate(collection,:remote => true)尚未被接受 https://github.com/mislav/will_paginate/pull/100
will_paginate(collection, :remote => true) not yet accepted https://github.com/mislav/will_paginate/pull/100
这篇关于Ruby-Rails 3-AJAXinate分页和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!