【发布时间】:2014-03-26 09:42:54
【问题描述】:
我想在 underscoreJS 中使用嵌套模板,并在父模板和子模板之间以相同的方式访问相同的变量。
//Backbone :
this.model = new Backbone.model.extend({backgroundColor:red});
this.$el.html(this.template(this.model.attributes);
//Underscore template:
<%=backgroundColor%>
<%=subTemplate()%>
//Underscore subtemplate:
<%=backgroundColor%>
JAshkenas 方法是将模型放在另一个对象中,如所述 here
//Backbone :
this.$el.html({model : this.model.attributes});
//But that means accessing "model" for every property, and having to pass "model" to each subtemplate
<%=model.backgroundColor%>
<%=subTemplate({model:model})%>
是否有更清洁/更短的解决方案?
【问题讨论】:
标签: javascript templates backbone.js underscore.js underscore.js-templating