[英]Access both indices in a nested loop in aurelia.io
我刚刚开始使用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>
我目前只能访问内部循环的索引。 有没有办法我也可以访问外循环的索引?
谢谢!
如评论中所述,您必须使用$parent
来访问父级的作用域。
考虑以下示例:
<template>
<div repeat.for="y of 5">
<div repeat.for="x of 5">
${$index} * ${$parent.$index} = ${$index * $parent.$index}
</div>
</div>
</template>
将$ parent。$ index用于父重复。
柱塞示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.