BackboneJS:您可以动态更改视图的模板吗?(BackboneJS: Can you change templates of a view on the fly?)

编程入门 行业动态 更新时间:2024-10-22 19:23:00
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.

更多推荐

本文发布于:2023-08-05 07:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您可以   视图   模板   动态   BackboneJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!