Angularjs ng repeat | filter,如何使用JavaScript中的新this.$index或key

Angularjs ng repeat | filter,如何使用JavaScript中的新this.$index或key,angularjs,filter,indexing,key,ng-repeat,Angularjs,Filter,Indexing,Key,Ng Repeat,当我筛选ng repeat时,.$index和key都会更改以反映对象在筛选数组中的位置 问题是我只能从JavaScript中看到未过滤的数组,因此,$index和key给出了一个意外的结果 HTML: <section ng-repeat="( key, place ) in places | filter: ({ name : placeName })" > <button ng-click='myFunc( this.$index )'>Pick {{place

当我筛选ng repeat时,.$index和key都会更改以反映对象在筛选数组中的位置

问题是我只能从JavaScript中看到未过滤的数组,因此,$index和key给出了一个意外的结果

HTML:

<section ng-repeat="( key, place ) in places | filter: ({ name : placeName })" >

<button ng-click='myFunc( this.$index )'>Pick {{place.name}}</button> <!-- same issue with key -->
<section>
我可以在数组上循环并找到$id或我自己的标识符,但如果我只需要一个索引,就可以传递给我的函数,该函数正在查看未过滤的数组,那么这似乎是浪费


谢谢。

不要传入索引,而是传入实际对象:

<section ng-repeat="( key, place ) in places | filter: ({ name : placeName })" >

<button ng-click='myFunc( place )'>Pick {{place.name}}</button> 
<!-- same issue with key -->
<section>
这将使测试myFunc方法变得更加容易,因为您提供了将在其中执行操作的对象

<section ng-repeat="( key, place ) in places | filter: ({ name : placeName })" >

<button ng-click='myFunc( place )'>Pick {{place.name}}</button> 
<!-- same issue with key -->
<section>
$scope.myFunc(place){
    console.log( place ); 
}