Pol*_*Pol 23 handlebars.js meteor
假设我想构建一个动态表.我如何在每个内部运行每个.如果唯一代表当前项目的变量是this.
{{#each by_width}}
{{#each by_height}}
{{this}} // how do refer to this from the outer loop?
{{/each}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
mu *_*ort 62
您可以../用来访问Handlebars模板中的父级:
{{#each by_width}}
{{#each by_height}}
w: {{../this}}
h: {{this}}
{{/each}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
那当然假设它by_height位于每个元素的内部by_width,如果它们都处于顶层,那么你需要另一个元素../:
{{#each by_width}}
{{#each ../by_height}}
w: {{../this}}
h: {{this}}
{{/each}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/ambiguous/PNTXw/