最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Access both indices in a nested loop in aurelia.io - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 8

As 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

发布评论

评论列表(0)

  1. 暂无评论