Skip to content

Instantly share code, notes, and snippets.

@ginpei
Created November 14, 2012 07:09
Show Gist options
  • Save ginpei/4070764 to your computer and use it in GitHub Desktop.
Save ginpei/4070764 to your computer and use it in GitHub Desktop.
How to pagination with backbone.js?
var PageModel = Backbone.Model.extend({ });
var PageView = Backbone.View.extend({
events: {
'click .other-page': 'open'
},
initialize: function() {
this.models = {};
},
open: function(id) {
var model = this.models[id];
if (model) {
this.model = model;
this.render();
}
else {
var model = new PageModel({ id: id });
model.bind('change', this.register, this);
model.bind('change', this.render, this);
model.fetch();
}
},
register: function(model) {
this.models[model.get('id')] = model;
this.model = model;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment