哪个更好的找到方法? $ filter或for in array?

时间:2014-12-27 14:51:38

标签: angularjs

我想找到哪个更好的方法在数组中找到一个值? 当我使用$ filter有时它不能正常工作。

1:

for (j = 0; j < $scope.tips.length; j++) {
    if ($scope.tips[j]["mid"] == cft.mid && 
        $scope.tips[j]["oid"] == cft.tips[inx].oid && 
        $scope.tips[j]["ot"] == cft.tips[inx].ot) {

        $scope.tips.splice(j,1);
    }
}

2:

var found2 = $filter('filter')($scope.tips, {mid: xmid, oid:xoid, ot:xot}, true)
if(found2.length) {
    $scope.tips.splice(found2.index, 1)
}

0 个答案:

没有答案