如何在过滤ng-repeat中返回所有数据?

时间:2017-03-13 10:01:32

标签: angularjs

我在PHP-Reports中使用自定义过滤器:

ng-repeat

并过滤:

item in filtered = (project.data.campaigns | filter:isStatus() | filter:isCategory()) | orderBy : 'created_at'

如果,如果 $scope.isStatus = function() { return function(item) { var status = $scope.inArray($scope.filterObj.status, item.status); console.log(status); return status; }; }; 为空,则返回$scope.filterObj中的所有项目?

简单,如果ng-repeat为false,则返回所有项

1 个答案:

答案 0 :(得分:2)

尝试:

$scope.isStatus = function() {
    return function(item) {
        // false if filterObj is null
        // since ECMAScript 5.1 you can also use Object.keys
        if ($scope.filterObj && Object.keys($scope.filterObj).length > 0) { 
            return $scope.inArray($scope.filterObj.status, item.status);
        }

        return item;
    };
};