I cannot seem to get hold of the parent varible from the child template, does anyone know how?
Current code:
<li class="ui-parent-field" >
<b>${ Name }</b>
{{if Options ===null}}
| <span data-field-name="${ Name }" data-field-type="${ Type }"></span>
{{/if}}
<br/>
${ Description }
{{if Options !==null}}
<div style="clear:both;">
<ul class="ui-child-list">
{{each Options}}
<li class="ui-child-field">
${ Name } : ${ Value } |
<span data-field-type="${ Type }" data-field-name="${ Name }"></span>
//NOTE should be:
<span data-field-type="${ Parent.Type }" data-field-name="${ Parent.Name }"></span> </li>
{{/each}}
</ul>
</div>
{{/if}}
</li>
This is a very crude example but I am basically throwing out some info into the view using jquery templates, I have a parent span item which contains Name + Type, then I am throwing out the child elements of this object if they exist, I want to access the Type property from the parent inside the each loop.
You can access the object that the entire template is bound to using $data. So, you would use something like:
<span data-field-type="${ $data.Type }" data-field-name="${ $data.Name }"></span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With