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中進行調試,然後通過查看下劃線的註釋源來確認它。 –