I just started learning JavaScript with Aurelia.io and I am currently trying to access the index of a 2D-Array that is rendered by Aurelia in order to bind the id attribute to the outer and inner index of the loop. The 2D-Array is rendered into a table with two loops:
<table>
<tr repeat.for="field of fields">
<td repeat.for="f of field">
<div class ="boardcell" id.one-time="$index" click.delegate="klick($index)">${f}</div>
</td>
</tr>
</table>
I am currently only able to access the index of the inner loop. Is there a way I can access the index of the outer loop, too?
Thanks!
I just started learning JavaScript with Aurelia.io and I am currently trying to access the index of a 2D-Array that is rendered by Aurelia in order to bind the id attribute to the outer and inner index of the loop. The 2D-Array is rendered into a table with two loops:
<table>
<tr repeat.for="field of fields">
<td repeat.for="f of field">
<div class ="boardcell" id.one-time="$index" click.delegate="klick($index)">${f}</div>
</td>
</tr>
</table>
I am currently only able to access the index of the inner loop. Is there a way I can access the index of the outer loop, too?
Thanks!
Share Improve this question asked Feb 3, 2017 at 12:01 ZnippyZnippy 479 bronze badges 1- 1 try some thing like $parent.$index – MMK Commented Feb 3, 2017 at 12:09
2 Answers
Reset to default 8As stated in the ment, you have to use the $parent
to access the parent's scope.
Consider this example:
<template>
<div repeat.for="y of 5">
<div repeat.for="x of 5">
${$index} * ${$parent.$index} = ${$index * $parent.$index}
</div>
</div>
</template>
Use $parent.$index for parent repeat.for index
Example Plunker