我一直在遵循一些教程,以便在backbone.js中将视图与模型绑定,但是当我在模型上设置新属性时,我的视图不会更改。
我目前在控制台中工作,正在将"tr“添加到"table”中。设置的新属性后,仅当我重新追加时更改才会出现。
代码如下:
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;
}发布于 2012-11-02 21:17:50
删除this.template = template.html行,您的代码就可以正常工作
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;
}
}); `https://stackoverflow.com/questions/13191497
复制相似问题