Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //分页器,对 collection 包了一层,以 Todo 那个举例:
- //
- // AppView 就是 Todo 里那个
- // 这里 AppView 用 PagerView 来实现分页
- AppView = Backbone.View.extend({
- initialize: function() {
- // ...
- // 正常对 Todos 这个 collection 进行事件绑定
- Todos.bind('add', this.add, this);
- // ...
- // 创建 PagerView
- this.pager = new PagerView({
- collection: Todos
- });
- // 绑定 PagerView 的 pageStart 事件
- this.pager.bind('pageStart', function(pageNumber) {
- this.pager.loadPage(pageNumber);
- }, this);
- },
- render: function() {
- // ... 正常的 render 逻辑
- // 把 pager 加入到 TodoList 这个元素后面
- this.pager.render();
- this.$(pager).insertAfter(this.el);
- }
- });
Add Comment
Please, Sign In to add comment