Rails 3 中的 jquery 无限页面与 will_paginate

发布于 2024-11-12 22:25:15 字数 78 浏览 6 评论 0原文

有谁知道我如何在 Rails 3 中使用 jquery 和 will_paginate 处理无尽的页面?我尝试了很多方法,但从来没有对我有用。

Does any one know how i can go about endless page with jquery and will_paginate in rails 3? I have tried so many ways but it has never worked for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁梦 2024-11-19 22:25:15

请参阅 Railscast #114 Endless Page

您应该能够以最少的成本使其与 Rails 3 一起使用修改(如果有)。

See Railscast #114 Endless Page

You should be able to make it work with Rails 3 with minimal modifications (if any).

遗弃M 2024-11-19 22:25:15

你的 endless-page.js 文件看起来像这样

   var currentPage = 1;
   var autoloading = false;
   if( total_number_of_paginaion_pages > 1) {
       autoloading = true;
     }

function checkScroll() {
  if (autoloading && nearBottomOfPage()) {
    currentPage ++;
    autoloading = false;
    $.ajax( {
      url: window.location,
      data: 'page=' + currentPage,
      beforeSend: function() {
        $('.loading-info').show()
      },
      complete: function(){
        $('.loading-info').hide()
       },
      success: function(data){
        eval(data);
       }
     });
  } 
}

function nearBottomOfPage() {
  return scrollDistanceFromBottom() < 150;
}

function scrollDistanceFromBottom(argument) {
  return $(document).height() - ($(window).height() + $(window).scrollTop());
}

$(window).bind('scroll', function (){
         checkScroll();
});  

在你的 js.erb 文件中看起来像这样

$('.results-center').append('<%=escape_javascript(render :partial => '/search/search_result') %>');
if(! pagination_last_page) {
  autoloading = true;
}

Your endless-page.js file will look something like this

   var currentPage = 1;
   var autoloading = false;
   if( total_number_of_paginaion_pages > 1) {
       autoloading = true;
     }

function checkScroll() {
  if (autoloading && nearBottomOfPage()) {
    currentPage ++;
    autoloading = false;
    $.ajax( {
      url: window.location,
      data: 'page=' + currentPage,
      beforeSend: function() {
        $('.loading-info').show()
      },
      complete: function(){
        $('.loading-info').hide()
       },
      success: function(data){
        eval(data);
       }
     });
  } 
}

function nearBottomOfPage() {
  return scrollDistanceFromBottom() < 150;
}

function scrollDistanceFromBottom(argument) {
  return $(document).height() - ($(window).height() + $(window).scrollTop());
}

$(window).bind('scroll', function (){
         checkScroll();
});  

And in your js.erb file will look something like this

$('.results-center').append('<%=escape_javascript(render :partial => '/search/search_result') %>');
if(! pagination_last_page) {
  autoloading = true;
}
天涯沦落人 2024-11-19 22:25:15

实现无限分页的最佳选择是使用 will_paginate / kaminari gem 和 jquery。

有一个关于如何实现无尽页面的好博客,希望能回答您的问题。看看

http://www.idyllic-software.com/blog/endless-page-using-jquery-and-will_paginate/

the best option for implementing endless pagination will be using will_paginate / kaminari gem with jquery.

there is a good blog on how to implement endless page and hopefully will answer your question.have a look

http://www.idyllic-software.com/blog/endless-page-using-jquery-and-will_paginate/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文