我想将新模型附加到视图并重新渲染视图。我能够首先渲染视图,但是我无法将该视图中的数据更改为新模型。
my_model_1 = Backbone.Model.extend({});
my_model_2 = Backbone.Model.extend({});
my_view = Backbone.View.extend({
initialize : function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
},
render : function(){
}
});
var view_instance = new my_view({ model: my_model_1 });
//Template gets rendered
try{
view_instance.changeModel(my_model_2);
}catch(e){console.log(e)};
try{
view_instance.set(my_model_2);
}catch(e){console.log(e)};
try{
view_instance.fetch(my_model_2);
}catch(e){console.log(e)};
try{
view_instance.model = my_model_2;
}catch(e){console.log(e)};
//Template should get updated with data from model 2
有什么建议吗?