从子 ng-repeat 访问父 ng-repeat 的索引 [英] Access index of the parent ng-repeat from child ng-repeat

查看:35
本文介绍了从子 ng-repeat 访问父 ng-repeat 的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用父列表 (foos) 的索引作为子列表 (foos.bars) 中函数调用的参数.

我发现有人推荐使用 $parent.$index 的帖子,但 $index 不是 $parent 的属性.

如何访问父ng-repeat的索引?

<div><div ng-repeat="b in foos.bars"><a ng-click="addSomething($parent.$index)">添加东西</a>

解决方案

我的示例代码是正确的,但问题出在我的实际代码中.不过,我知道很难找到这样的例子,所以我会回答这个问题,以防其他人正在寻找.

<div><div ng-repeat="b in foos.bars"><a ng-click="addSomething($parent.$index)">添加东西</a>

I want to use the index of the parent list (foos) as an argument to a function call in the child list (foos.bars).

I found a post where someone recommends using $parent.$index, but $index is not a property of $parent.

How can I access the index of the parent ng-repeat?

<div ng-repeat="f in foos">
  <div>
    <div ng-repeat="b in foos.bars">
      <a ng-click="addSomething($parent.$index)">Add Something</a>
    </div>
  </div>
</div>

解决方案

My example code was correct and the issue was something else in my actual code. Still, I know it was difficult to find examples of this so I'm answering it in case someone else is looking.

<div ng-repeat="f in foos">
  <div>
    <div ng-repeat="b in foos.bars">
      <a ng-click="addSomething($parent.$index)">Add Something</a>
    </div>
  </div>
</div>

这篇关于从子 ng-repeat 访问父 ng-repeat 的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆