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

后端 未结 5 1321
情歌与酒
情歌与酒 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:18

    Answer: {{@../index}}

    From the Handlebars docs (see bottom of 'each' helper section):

    "Nested each blocks may access the interation variables via depted paths. To access the parent index, for example, {{@../index}} can be used."

    NOTE: I'm using v1.3 so it's at least that old.

    REMINDER: Helpers are your last best option. 9/10 there is a better solution.

提交回复
热议问题