简体   繁体   English

根据外部ng-repeat索引过滤内部ng-repeat

[英]Filter inner ng-repeat based on index of outer ng-repeat

I am trying to get the index of parent ng-repeat and in inner ng-repeat filter the data based of that. 我正在尝试获取父级ng-repeat的索引,并在内部ng-repeat过滤器中基于该数据。 Trying to use the below code but it is not working. 尝试使用以下代码,但不起作用。

<div class="boxStyle" ng-repeat="priorityItem in priorityBox" data-tasktype= '{{$index+1}}' ui-drop-listener='dropListener' data-model='someArrays' > {{priorityItem.name}}
    <div ui-draggable ng-repeat="item in someArrays  | filter: {tasktype: "+ '{{$parent.$index}}' +" | orderBy: 'priority'" data-index='{{$index}}' data-taskid='{{item.taskid}}' data-priority='{{item.priority}}' class='btn btn-info btn-block'>{{item.name}}
    </div>
</div>

Here is a plunker that does the job. 是一个干活的人。 It is not pretty because it duplicates the $index in order to make it easily accessible from the inner ng-repeat. 它不是很漂亮,因为它复制了$ index以便从内部ng-repeat轻松访问它。
I would introduce a new custom filter to do the job. 我将介绍一个新的自定义过滤器来完成这项工作。 This is the line that introduces a new variable which stores the parent index: 这行代码引入了一个新变量来存储父索引:

<div ng-init="parentIndex = $index"></div>

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM