handlebars.js “each” loop inside another “each” loop 3

后端 未结 2 1998
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 04:09

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_widt         


        
相关标签:
2条回答
  • 2021-02-01 04:51

    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/

    0 讨论(0)
  • 2021-02-01 05:03

    Don't write {{../this}} but {{..this}}.

    0 讨论(0)
提交回复
热议问题