简体   繁体   English

rails 3,简单数组的Kaminari分页

[英]rails 3,Kaminari pagination for an simple Array

For paginating a common array I got this solution,为了对公共数组进行分页,我得到了这个解决方案,

@arr_name = Kaminari.paginate_array(@arr_name).page(params[:page]).per(PER_PAGE_RECORDS) @arr_name = Kaminari.paginate_array(@arr_name).page(params[:page]).per(PER_PAGE_RECORDS)

PER_PAGE_RECORDS is a variable with value as per needed for pagination. PER_PAGE_RECORDS是一个变量,其值根据分页需要。

Any better Ideas??有更好的想法吗??

Also to have an ajax call for using pagination one can use this,还有一个 ajax 调用使用分页可以使用这个,

In your view,在你看来,

give id to your div tab为您的 div 标签提供 id

div id="paginate"

and inside it在里面

<%= paginate @arr_name, :remote => true %> <%= 分页@arr_name, :remote => true %>

And in js response file put,并在js响应文件中放置,

$('#paginate').html('<%= escape_javascript(paginate(@arr_name, :remote => true).to_s) %>'); $('#paginate').html('<%= escape_javascript(paginate(@arr_name, :remote => true).to_s) %>');

So your requests will be AJAX.所以您的请求将是 AJAX。

Thanks.谢谢。

This is the only available helper method to paginate an array object using Kaminari.这是使用 Kaminari 对数组 object 进行分页的唯一可用辅助方法。 Another alternative is, as suggested solution in kaminari wiki page , add the instance methods to the array object.另一种选择是,如kaminari wiki 页面中建议的解决方案,将实例方法添加到数组 object。

If you are trying a common solution based on the ActiveModel return type (.all returns array and.where returns ARL) then following is an workaround.如果您正在尝试基于 ActiveModel 返回类型的通用解决方案(.all 返回数组,.where 返回 ARL),那么以下是一种解决方法。

unless @arr_name.kind_of?(Array)
  @arr_name = @arr_name.page(params[:page]).per(PER_PAGE_RECORDS)
else
  @arr_name = Kaminari.paginate_array(@arr_name).page(params[:page]).per(PER_PAGE_RECORDS)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM