I have a backbone view like so
window.InputView = Backbone.View.extend({
tagName:'input',
className:'',
attributes:{},
initialize:function(){
this.attributes=this.model.attributes;
this.el = this.make(this.tagName,this.attributes,'');
}
});
The problem I am having is that When I modify the attributes hash of the View it does not reflect on the el,
So I have to do something like this this.el = this.make(this.tagName,this.attributes,'');
for the changes to reflect .
Is this the only way , or is there a better way to do it ? like automate it ?
To automate whatever you’re trying to do when your model changes you need to bind a method to the change event of the model. In your initialize method you’d need something like:
and then define that method later on in your view:
Now, anytime the model associated to that view changes the
updateElementmethod will run.