按状态过滤ng-repeat

Filter ng-repeat by status

本文关键字:ng-repeat 过滤 状态      更新时间:2023-09-26

我有一个下拉菜单值在它。它们是通过.value属性访问的。我有一个ng-repeat在一个div上,它重复了很多数据。这些数据具有状态。当用户选择通过下拉菜单中的状态进行过滤时,我想通过他们选择的任何statusng-repeat中的status来过滤ng-repeat。这里有一个更好的例子说明我的意思:

data-ng-repeat="stackoverflow in overflows| filter:stackoverflow.property.status===status.value"

在我的情况下,我需要访问stackoverflow.property.status并将其与下拉列表中的任何状态进行比较。

您需要做如下操作:

<span ng-repeat="stackoverflow in overflows | filter: { status : selectedStatus }"></span>

selectedStatus将是下拉列表中ng-model的值

你可以这样写

ng-repeat="stackoverflow in overflows | filter: { locations: [{ status: status.value }] }"

在这种情况下,编写自己的函数并使用它进行过滤反而更容易。在这种情况下,我有一个函数搜索,我传递给过滤器。很适合我。

我在另一个问题上找到了一个答案。你可以在这里查看:http://jsfiddle.net/suCWn/

$scope.search = function (shop) {
    if ($scope.selectedCityId === undefined || $scope.selectedCityId.length === 0) {
        return true;
    }
    var found = false;
    angular.forEach(shop.locations, function (location) {          
        if (location.city_id === parseInt($scope.selectedCityId)) {
            found = true;
        }
    });
    return found;
};`
Angularjs过滤器嵌套对象