I have a 2D array in a JSON object (called table ;)
data = {
tableID : "testTable",
table : [
[{type:'a', value:'x'},{type:'a', value:'y'},{type:'a', value:'z'}],
[{type:'a', value:'x'},{type:'a', value:'y'},{type:'a', value:'z'}],
[{type:'a', value:'x'},{type:'a', value:'y'},{type:'a', value:'z'}]
]
};
And have been successfully rendering it out with handlebars using the template:
<table id = "{{tableID}}-table">
{{#each table}}
<tr id = "{{../tableID}}-row-{{@index}}">
{{#each this}}
<td id = "{{../../tableID}}-row-{{../index}}-col-{{@index}}">
{{this.type}}-{{this.value}}
</td>
{{/each}}
</tr>
{{/each}}
</table>
However, in the td tag id I can't seem to access the parent index {{../index}} - the index of the row. Nothing is returned:
<td id = "testTable-row--col-x">
However, I can access the index of the current context {{@index}}.
Any ideas??
Many many thanks in advance!!
Rich
p.s. Using 1.0.0-rc.3
This is an open issue/feature on handlebar. You can check the progress for the same here
However you can check the workaround here
Since Handlebars version 2.0.0, you can use
{{@../index}}
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