JsRender. Nested loop by the object of top loop
Asked Answered
W

1

2
{{for players}}
   <tr>
    {{for ~root.players}}
        {{if index == #index}}
            <td>*</td>
        {{else}}
            <td>{{index}}+{{:#getIndex()}}</td>
        {{/if}}
    {{/for}}
{{/for}}

I want to get access to #index of the top loop in nested loop by the players to compare top loop #index and nested loop #index. Maybe it is possible to access to top loop current item?

Weaponeer answered 23/12, 2015 at 14:50 Comment(0)
W
3

There are several ways of getting to parent views. See http://www.jsviews.com/#views: get(type) method, Accessing "parent" data, from nested views, etc.

For example you can create a contextual template parameter: ~index

{{for players}}
   <tr>
    {{for ~root.players ~index=#index}}
        {{if ~index == #index}}
            <td>*</td>
        {{else}}
            <td>{{:~index}}+{{:#getIndex()}}</td>
        {{/if}}
    {{/for}}
   </tr>
{{/for}}
Wormeaten answered 23/12, 2015 at 18:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.