JsRender. Nested loop by the object of top loop

戏子无情 提交于 2019-12-18 09:08:08

问题


{{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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!