Pradeep
Pradeep

Reputation: 4872

Access parent item inside a loop in 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>

How to get the parent array's LocationId inside if statement which is mentioned in between **.

Upvotes: 7

Views: 6541

Answers (1)

Sergii
Sergii

Reputation: 1320

You can introduce variable which will be visible inside loop (In official documentation: Setting contextual template parameters, accessible in all nested contexts as ~nameOfParameter)

<select id="Test" TestAttr="{{:LocationId}}">  
    {{for #parent.parent.data.Location ~locationId=LocationId}}
       <option value="{{:~locationId}}"...


EDITED POSTSCRIPT:

The above link is to previous documentation, now superceded.

For current documentation, see Accessing parent data.

See also this stackoverflow question

Upvotes: 13

Related Questions