加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – kaminari ajax分页不更新分页

发布时间:2020-12-17 01:58:56 所属栏目:百科 来源:网络整理
导读:我正在使用kaminari gem在rails3中实现分页. 我一直在关注github的代码 https://github.com/amatsuda/kaminari_example/commits/ajax 不幸的是,以下代码 jQuery('#paginator').html('%= escape_javascript(paginate(@recipes,:remote=true).to_s) %'); 似乎
我正在使用kaminari gem在rails3中实现分页.

我一直在关注github的代码
https://github.com/amatsuda/kaminari_example/commits/ajax

不幸的是,以下代码

jQuery('#paginator').html('<%= escape_javascript(paginate(@recipes,:remote=>true).to_s) %>');

似乎不起作用.

我的javascript用于做什么用户选择页面是什么

  jQuery('a','nav.pagination').click(function(){
         // get the page value from href
          var page = jQuery(this).attr('href').replace('/home/index?page=','');
          jQuery.getJSON('?page='+page,function(data){
                 for (var r in data){
                   results.push(data[r]);
          });
              showResults(results,(page-1)*10);
              jQuery('#paginator').html('<%= escape_javascript(paginate(@recipes,:remote=>true).to_s) %>');
  });

showResults函数通过JSON运行并创建一堆html元素.
一切都很好,除了在重新加载结果时分页没有更新以显示当前页面.

我在firebug中没有任何错误,我使用Rails 3和ruby 192.

解决方法

你确定HTML中的paginator有’#paginator’元素吗?
我的意思是,以下代码是否返回Firebug上的元素?

jQuery('#paginator')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读