Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

javascript - 从子ng-repeat访问父ng-repeat的索引(Access index of the parent ng-repeat from child ng-repeat)

I want to use the index of the parent list (foos) as an argument to a function call in the child list (foos.bars).(我想使用父列表的索引(foos)作为子列表(foos.bars)中函数调用的参数。)

I found a post where someone recommends using $parent.$index, but $index is not a property of $parent .(我找到了一个帖子,有人建议使用$ parent。$ index,但$index不是$parent的属性。)

How can I access the index of the parent ng-repeat ?(如何访问父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>
  ask by Coder1 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...