BackboneJS:您可以动态更改视图的模板吗?(BackboneJS: Can you change templates of a view on the fly?)
您可以通过提交模板选项来更改骨干视图的模板吗? 以下代码似乎不起作用:
@company_location= new window.ArtistLocationForm({template: JST["templates/new_company_location"]})Can you change the template of a backbone view by submitting a template option? Code below doesn't seem to work:
@company_location= new window.ArtistLocationForm({template: JST["templates/new_company_location"]})最满意答案
不是开箱即用的。
但是传入构造函数的所有数据都会分配给视图实例上的this.options,因此在render函数中实现它应该非常简单,例如:
render: function(){ var templateFn = this.options.template || this.template; this.$el.html(templateFn(this.model.attributes)); return this; }应该管用。
Not out-of-the-box.
But all data passed in to the constructor is assigned to this.options on your view instance, so implementing it in the render function should be pretty easy, something like:
render: function(){ var templateFn = this.options.template || this.template; this.$el.html(templateFn(this.model.attributes)); return this; }should work.
更多推荐
发布评论