如何从与AngularJS滤波器阵列删除项目吗? [英] How to remove item from array with filter in AngularJS?

查看:123
本文介绍了如何从与AngularJS滤波器阵列删除项目吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 TR 点击没有任何过滤器,我的功能方法Array.splice()的作品。数组中的索引以正确的顺序,因此方法Array.splice()的作品。

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.

当过滤器是启用,阵列中的索引中不相同的顺序更新并仍。因此,方法Array.splice()删除错误的项目。

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 ?

推荐答案

最简单的解决办法是改变你remove函数参加该项目,而不是指数。

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);
        }
    }
}

例Plunker: http://plnkr.co/edit/51SNVMQjG3dsmpYI5RyY?p= preVIEW

这篇关于如何从与AngularJS滤波器阵列删除项目吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆