Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  147] [ 6]  / answers: 1 / hits: 49181  / 10 Years ago, thu, may 22, 2014, 12:00:00

When I click on tr without any filter, my function array.splice() works. Indexes in the array are in the correct order, so the array.splice() works.



When the filter is enable, Indexes in the array are not updated and still in the same order. So array.splice() removes the wrong item.



    <span ng-click=orderP0 = 'statut_name'; reversePO=!reversePO>order</span>

<tr ng-repeat=project in projects | orderBy : orderPO : reverse track by $index ng-click=remove($event,$index,projects)>
<span class=label ng-bind=project.statut_name></span>
</tr>

$scope.remove = function($event,index,array){
array.splice(index,1);
};


How to update index in the array ? Or How to removes the right item ?


More From » arrays

 Answers
15

The simplest solution would be to change your remove function to take in the project instead of the index.



$scope.remove = function(project){
for(var i = $scope.projects.length - 1; i >= 0; i--){
if($scope.projects[i].statut_name == project.statut_name){
$scope.projects.splice(i,1);
}
}
}


Example Plunker: http://plnkr.co/edit/51SNVMQjG3dsmpYI5RyY?p=preview


[#70892] Wednesday, May 21, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josuea

Total Points: 609
Total Questions: 121
Total Answers: 104

Location: South Georgia
Member since Fri, Nov 13, 2020
4 Years ago
josuea questions
;