Handlebars.js - access to the parent index from a 2D array

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 they successfully completed it using the rudders 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 id of the td tag, I can’t access the parent index {{../index}} - the row index. Nothing returns:

<td id = "testTable-row--col-x">

However, I can access the current context index {{@index}}.

Any ideas?

Thank you very much in advance!

Rich

ps use 1.0.0-rc.3

+5
source share
2 answers

This is an open problem / function on the steering wheel. You can check the progress for the same here.

However, you can check the workaround here

+2
source

Handlebars 2.0.0

{{@../index}}
+1

All Articles