在jsrender中访问循环内的父项

Pra*_*eep 7 jsrender

<select id="Test" TestAttr="{{:LocationId}}">              
       {{for #parent.parent.data.Location}}                         
                  <option value="{{:LocationId}}" {{if LocationId= *#parent.parent.data.LocationId*}}selected{{/if}}>{{:#parent.parent.data.LocationId}}</option>                            
       {{/for}}
</select>
Run Code Online (Sandbox Code Playgroud)

如何在**之间提到的if语句中获取父数组的LocationId.

Ser*_*gii 13

您可以引入在循环内可见的变量(在官方文档中:设置上下文模板参数,可在所有嵌套上下文中访问~nameOfParameter)

<select id="Test" TestAttr="{{:LocationId}}">  
    {{for #parent.parent.data.Location ~locationId=LocationId}}
       <option value="{{:~locationId}}"...
Run Code Online (Sandbox Code Playgroud)