I’ve been following some tutorials to bind the view with the model in backbone.js, but my view does not change when I set a new attribute on the model.
I’m currently working form the console and am appending the “tr” to a “table”. After setting the new attributes of the , changes only appear if I re-append.
Code below:
window.ListView = Backbone.View.extend({
tagName:"tr",
template: _.template("<td><%= first%></td><td><%= last%></td><td><%= sex%></td><td><%= height></td><td><%= weight%></td>"),
initiliaze: function(){
_.bindAll(this, 'render');
this.model.bind('change', this.render, this);
this.template = template.html;
},
render:function () {
this.$el.html(this.template(this.model.toJSON()));
return this;
}
Remove the line
this.template = template.htmland your code works fine