stloc
stloc

Reputation: 1548

handlebarsjs how to imbricated many loop/each

http://jsfiddle.net/0ttb7pug/1/

I do not have the desired result, only first loop executed

{{#each loop1}}
<ul>{{val1}}
    {{#each loop2}}
        <li>{{val2}}</li>
    {{/each}}
</ul>
{{/each}}

Upvotes: 0

Views: 36

Answers (1)

Grafpaper10
Grafpaper10

Reputation: 521

Since your second {{#each}} is within the first, its context has changed to that of each object in the first array. To resolve your issue, you need to get access to the root context of your template data (or at least the context above), which can be achieved with either ../loop2 (which takes you up one context) or @root.loop2 (which takes you to the top-most context)

{{#each loop1}}
  <ul>{{val1}}
    {{#each ../loop2}} //or @root.loop2
      <li>{{val2}}</li>
    {{/each}}
  </ul>
{{/each}}

Upvotes: 1

Related Questions