Handlebars.js: How to access parent index in nested each?

后端 未结 5 1329
情歌与酒
情歌与酒 2020-12-12 20:57

How to access parent @index value in each-loop?

Tried the following:

{{#each company}}
{{#each employee}}
  {{../@index}} // how to access company in         


        
5条回答
  •  鱼传尺愫
    2020-12-12 21:23

    It looks like there's a new syntax in Ember v2.2.0. I tried all the answers here and they didn't work for me.

    What I found worked was naming the parent loop's index and the child loop's index.

    {{#each parents as |parent parentIndex|}}
        {{parentIndex}}
        {{#each children as |child childIndex|}}
            {{parentIndex}}
            {{childIndex}}
        {{/each}}
    {{/each}}
    

提交回复
热议问题