0
我想在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})%>
是否有一个更清洁/更短的解决方案吗?
我也为此而努力,直到我发现生成的模板功能,同时在Chrome中进行调试,然后通过查看下划线的注释源来确认它。 –