I am working to this web-app, todos.js, which is well documented at this url.
I would like to add an option in order to display a limited number of items per page.
Here my attempt which works but I am not sure if it is the right way to do this task:
var AppView = Backbone.View.extend({
firstPage: 0,
perPage: 2,
counter: 0,
......
addOne: function addOne (todo)
{
var view,
isIntoRange;
view = new TodoView({
model: todo
});
isIntoRange = (
this.counter >= (this.firstPage * this.perPage)
&&
this.counter < (this.firstPage * this.perPage) + this.perPage
);
if (isIntoRange) {
this.$("#todo-list").append(view.render().el);
}
this.counter += 1;
},
addAll: function() {
Todos.each(this.addOne);
},
.....
});
Having said that backbone-paginator is a good choise, I will not modify the method
addOnefor performing this task:Rather, I will add a new method
showTasksthat can accept two parameter:firstPageandperPageAnd then, since this method should be called from a link, I will use
backbone.routerto render the page: