假设我想建立一个动态表。我如何在每个内部运行每个。如果表示当前项目的唯一变量是this.
{{#each by_width}}
{{#each by_height}}
{{this}} // how do refer to this from the outer loop?
{{/each}}
{{/each}}
假设我想建立一个动态表。我如何在每个内部运行每个。如果表示当前项目的唯一变量是this.
{{#each by_width}}
{{#each by_height}}
{{this}} // how do refer to this from the outer loop?
{{/each}}
{{/each}}
您可以使用../来访问 Handlebars 模板中的父级:
{{#each by_width}}
{{#each by_height}}
w: {{../this}}
h: {{this}}
{{/each}}
{{/each}}
这当然假设它by_height在的每个元素内by_width,如果它们都在顶层,那么你需要另一个../:
{{#each by_width}}
{{#each ../by_height}}
w: {{../this}}
h: {{this}}
{{/each}}
{{/each}}
演示:http: //jsfiddle.net/ambiguous/PNTXw/
不写{{../this}}但是{{..this}}。