Created
November 14, 2012 07:09
-
-
Save ginpei/4070764 to your computer and use it in GitHub Desktop.
How to pagination with backbone.js?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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