问题
{{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?
回答1:
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}}
来源:https://stackoverflow.com/questions/34438236/jsrender-nested-loop-by-the-object-of-top-loop