I am working with the Todos example application bundled with the latest version of Backbone (0.9.2), studying Backbone.js. My question is: why is the application designed to trigger a rendering event twice when adding a model to the Todos collection?
If I put this line in the TodoView rendering function:
// Re-render the titles of the todo item. render: function() { console.log("Rendering!"); this.$el.html(this.template(this.model.toJSON()));
Then "Rendering!" appears twice in the console. I understand this is due to the fact that the view binds the model change event to the view rendering:
initialize: function() { this.model.bind('change', this.render, this);
And the render is called in addOne, which is bound to the Todos add event:
addOne: function(todo) { var view = new TodoView({model: todo}); this.$("#todo-list").append(view.render().el); },
But is this a standard practice for dual rendering design? It seems like the presentation should be done when creating (or entering the DOM), and then again if the base model changes. In this case, nothing changes, but the render is called twice.
Again, I'm just learning Backbone, so I might have a major misunderstanding that leads to my confusion.
jcady
source share