在aurelia.io的嵌套循环中访问两个索引

Zni*_*ppy 2 javascript arrays aurelia

我刚刚开始使用Aurelia.io学习JavaScript,并且当前正在尝试访问Aurelia渲染的2D数组的索引,以便将id属性绑定到循环的外部和内部索引。2D数组通过两个循环呈现到表中:

<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>
Run Code Online (Sandbox Code Playgroud)

我目前只能访问内部循环的索引。有没有办法我也可以访问外循环的索引?

谢谢!

Tra*_*avo 5

如评论中所述,您必须使用$parent来访问父级的范围。

考虑以下示例:

<template>
  <div repeat.for="y of 5">
    <div repeat.for="x of 5">
      ${$index} * ${$parent.$index} = ${$index * $parent.$index}
    </div>
  </div>
</template>
Run Code Online (Sandbox Code Playgroud)