I’m messing with backbone.js Todos for the first time. I’m trying to add a timer each Todo, which is fine, but the timer won’t refresh until I refresh the page, and I want it to refresh every second.
The AppView contains this:
window.AppView = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'addAll');
Todos.bind('refresh', this.addAll);
Todos.fetch();
},
addAll: function() {
Todos.each(this.addOne);
},
}
So I figured I could reload it every second like this:
window.setInterval(function(){
window.Todos.refresh();
}, 1000);
addAll is called and I get no errors on the console, but the view does not update.
What am I doing wrong?
Figured out a way to do it by manually triggering the model’s change event. This works because the view’s render function is bound to the model by
this.model.bind('change', this.render, this);(In this scenario,
Todosis a collection ofTodomodels