AngularJS:在原始数组中找到过滤值的索引位置 [英] AngularJS: find the index position of filtered value in the original array
本文介绍了AngularJS:在原始数组中找到过滤值的索引位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$scope.data = [{"name": "吉姆",身份证":25},{"name": "杰瑞",身份证":27},{"name": "丽思卡",身份证":20}];<div ng-repeat="person in data | filter: {id:20}">{{parent_index}}
parent_index - 实际数组中过滤元素的索引.
在这个例子中,parent_index 应该返回 2.如何找到它?
解决方案
在原数组中找到过滤值的索引位置
试试这个:
{{data.indexOf(person)}}
输出: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屋!
查看全文