handlebars.js“每个”循环内的另一个“每个”循环3 [英] handlebars.js “each” loop inside another “each” loop 3
本文介绍了handlebars.js“每个”循环内的另一个“每个”循环3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个
。 {{ #each by_width}}
{{#each by_height}}
{{this}} //如何从外部循环引用它?
{{/ 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}}
Suppose I want to build a dynamic table. How do I run each inside each. If the only varible that represents current item is this
.
{{#each by_width}}
{{#each by_height}}
{{this}} // how do refer to this from the outer loop?
{{/each}}
{{/each}}
解决方案
You can use ../
to access the parent in a Handlebars template:
{{#each by_width}}
{{#each by_height}}
w: {{../this}}
h: {{this}}
{{/each}}
{{/each}}
That of course assumes that by_height
is inside each element of by_width
, if they're both at the top level then you'd need another ../
:
{{#each by_width}}
{{#each ../by_height}}
w: {{../this}}
h: {{this}}
{{/each}}
{{/each}}
Demo: http://jsfiddle.net/ambiguous/PNTXw/
这篇关于handlebars.js“每个”循环内的另一个“每个”循环3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文