通过 Backbone 视图渲染模板时,您通常会得到一些看起来像这样的代码:
ShirtView = {
template: JST["/templates/shirt_template"],
el: ".shirt-element"
render: function() {
var html = this.template({color: this.model.color, size: this.model.size});
this.$el.html(html);
}
}
这一切都很好,您的模板将呈现您想要的属性。但如果this.model.color
发生变化,则不会反映在视图中。然后,您可以使用诸如 modelbinder 之类的东西将视图中的元素显式绑定到您的模型,但这意味着向您的视图引入额外的代码。
我想知道是否有任何模板引擎,例如 Mustache 或 Handlebars,可以在模型更改时自动更新属于属性对象中的字段的元素,而无需我在视图中指定它?