$index的元素变化,而使用过滤器如何获得正确的索引元素angularjs

$index of element changes while using filter how to get correct index of element angularjs?

本文关键字:元素 何获得 索引 angularjs 过滤器 变化 index      更新时间:2023-09-26

当我使用过滤器时,元素的索引正在改变,当我删除一个元素时,它正在删除另一个元素,如何获得该元素的确切$索引?

 <div class="repeater" ng-repeat="student in students | filter : query">
 <button type="button" class="close pull-right" ng-click="remove($index)">&times;</button>
 $scope.remove = function(id){
     $scope.students.splice(id,1);
 };

最好使用student对象本身。

<button type="button" class="close pull-right" ng-click="remove(student)">&times;</button>

$scope.remove = function(student){
     $scope.students.splice($scope.students.indexOf(student),1);
 };