在分页Backbone.js的 [英] Pagination in Backbone.js

查看:259
本文介绍了在分页Backbone.js的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有这个一个组成部分,但根据我所看到的,你必须创建具有扩展组件一个新的集合。是否有另一种方式来做到分页骨干?

I know that there is a component for this but based on what i see you have to create a new collection with the component extended. Is there another way to do pagination in backbone?

我需要的仅仅是一个previous和下一步按钮限制每页的项目12.我一直在创造它于JavaScript(不适用于生产环境的一个很好的解决方案)。任何想法?

All i need is just a previous and next button limit the items per page to 12. i've been creating it on javascript ( not a good solution for production environment ). Any ideas?

推荐答案

由于骨干网收集工作强调扩大的方法,你可能希望创建辅助分页方法非常简单。我用的是这样的:

Since Backbone collection has underscore methods extended, you might want to create helper pagination method very easy. I use something like :

var Paginated = Backbone.Collection.extend({

    pagination : function(perPage, page) {
       page = page-1;
       var collection = this;
       collection = _(collection.rest(perPage*page));
       collection = _(collection.first(perPage));    
       return collection.map( function(model) { return model.toJSON() } ); 
    }
});

这将返回您的收藏中的toJSON,你可以用它在玩的jsfiddle: http://jsfiddle.net/YHmrp/2/

This returns toJSON of your collection, you may play with it in the jsfiddle : http://jsfiddle.net/YHmrp/2/

这篇关于在分页Backbone.js的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆