过滤多个值

时间:2015-08-14 20:21:50

标签: angularjs filter

我的项目应该有多个(例如类别)。现在我想将我的项目过滤到这些类别。 我认为在不使用自定义过滤器的情况下使用filter-directive无法完成任务,对吗?

我提出了一个解决方案,但对我来说看起来很脏又错:

$scope.filterList = function (item) {
    var found = false;
    var allFalse = true;
    angular.forEach(item.attributes, function (value, key) {
        if ($scope.activeAttributes[value.name] === true) {
            found = true;
        }
    });
    angular.forEach($scope.activeAttributes, function (value, key) {
        if (value === true) {
            allFalse = false;
        }
    });
    $log.log("length: " + Object.keys($scope.activeAttributes).length);
    if (found === true || Object.keys($scope.activeAttributes).length === 0 || allFalse === true) {
        return true;
    }
};

Demo JSFiddle of my code

我想到Angular,代码应该很简单,大部分工作都应该由Angular完成。如果我需要过滤更多属性怎么办?

0 个答案:

没有答案
相关问题