How do I use nested iterators with Mustache.js or Handlebars.js?

后端 未结 6 1769
后悔当初
后悔当初 2020-12-24 01:52

I would like to use handlebars.js or mustache.js to iterate over a list of families, and then iterate over that family\'s members. Inside of both loops, I want to display pr

6条回答
  •  囚心锁ツ
    2020-12-24 02:01

    You can reference the parent loop variable and index with the ../ operator:

    {{#each families}}
      {{#each this.members}}
        

    Current member: {{ this.name }} (this = inner loop itterator)

    Current family: {{ ../this.title }} (../this = parent loop itterator)

    Current member index: {{ @index }}

    Current family index: {{ @../index }}

    {{/each}} {{/each}}

提交回复
热议问题