I am going to propose a solution that contradicts your assumption: "The view should be a template agnostic."
If you call render()at any time when something has changed in the Model, you will blink in your browser, especially if the template is large.
My recommendation is a separate renderview that occurs only once when the view is visualized and several helper methods updatethat are responsible for updating small fragments of the view associated with specific attributes of the model.
For instance:
var MyView = Backbone.View.extend({
initialize: function(){
this.model.on( "change:title", this.updateTitle, this );
this.model.on( "change:description", this.updateDescription, this );
},
render: function(){
this.$el.html( this.template( this.model.toJSON() ) );
},
updateTitle: function(){
this.$el.find( ".title" ).html( this.model.get( "title" ) );
},
updateDescription: function(){
this.$el.find( ".description" ).html( this.model.get( "description" ) );
},
})
source
share