本文介绍了如何在嵌套的 ng-repeat 中访问超级父级的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问最外层 ng-repeat 的索引.

<div ng-repeat=""><div ng-repeat="">//我想在这里获取外部ng-repeat的$index

解决方案

使用ng-init设置外层索引:

然后您可以在其他范围内使用 outerIndex.

Angular 文档中专门有这个例子

I want to access the index of the outermost ng-repeat.

<div ng-repeat="">
  <div ng-repeat="">
    <div ng-repeat="">
      //I want to get the $index of outer ng-repeat here
    </div>
  </div>
</div>
解决方案

Use ng-init to set the outer index:

<div ng-repeat="" ng-init="outerIndex = $index">

Then you can use outerIndex in the other scopes.

Angular documentation has this example specifically

这篇关于如何在嵌套的 ng-repeat 中访问超级父级的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:34