您可以通过提交模板选项来更改主干 View 的模板吗?下面的代码似乎不起作用:
@company_location= new window.ArtistLocationForm({template: JST["templates/new_company_location"]})
最佳答案
不是开箱即用的。
但是传入构造函数的所有数据都会分配给 View 实例上的 this.options,因此在渲染函数中实现它应该非常简单,如下所示:
render: function(){
var templateFn = this.options.template || this.template;
this.$el.html(templateFn(this.model.attributes));
return this;
}
应该可以。
关于javascript - Backbone JS : Can you change templates of a view on the fly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15873217/