AngularJS:发现过滤值的原始数组中的索引位置 [英] AngularJS: find the index position of filtered value in the original array
本文介绍了AngularJS:发现过滤值的原始数组中的索引位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ scope.data = [
{
名:吉姆,
ID:25
},
{
名:杰里
ID:27
},
{
名:Rithika
ID:20
}
]; < DIV NG重复=个人数据|过滤器:{ID:20}>
{{parent_index}}
< / DIV>
parent_index - 指数的实际阵列中的过滤元件的
在这个例子中,parent_index应该返回2.如何找呢?
解决方案
找到原来的数组中的滤波值的索引位置
块引用>试试这个:
< DIV NG重复=数据的人|过滤器:{ID:20}>
{{data.indexOf(人)}}
< / DIV>输出:
2
演示<大骨节病> 小提琴 骨节病>
$scope.data = [ { "name": "Jim", "id" : 25 }, { "name": "Jerry", "id": 27 }, { "name": "Rithika", "id": 20 } ]; <div ng-repeat="person in data | filter: {id:20}"> {{parent_index}} </div>
parent_index - Index of the filtered element in the actual array.
In this example, parent_index should return 2. how to find it?
解决方案find the index position of filtered value in the original array
Try this one:
<div ng-repeat="person in data | filter: {id:20}"> {{data.indexOf(person)}} </div>
Output:
2
Demo Fiddle
这篇关于AngularJS:发现过滤值的原始数组中的索引位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文