我正在寻找angularjs多条件过滤器,如this arr in array | filter:filters.search | filter:{company: selectedName} | filter:{voucher_type: both }
它工作但不过滤所有条件我粘贴我的完整代码。 filter:{company: selectedName} | filter:{voucher_type: both }
此过滤器步骤在我的代码中是错误的。@感谢您的回复
<html >
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<title>search</title>
</head>
<body>
<div ng-app="app" ng-controller="mainCtrl">
<div><select ng-model="selectedName" ng-options="x for x in names">
</select>
</div>
<input type="text" ng-model="both">
<div>Search by Name: <input type="text" ng-model="filters.search"></div>
<div ng-repeat="arr in array | filter:filters.search | filter:{company: selectedName} | filter:{voucher_type: both } ">
<span ng-bind="arr.name"></span>
</div>
</div>
<script type="text/javascript" src="js/angular.min.js"></script>
<script src="js/ui-bootstrap-tpls-0.9.0.js"></script>
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('mainCtrl', function($scope) {
$scope.names = ["x", "y"];
$scope.filters = {
x: false,
company: '',
search: ''
};
$scope.actions = {
updateyCompany: function () {
if($scope.filters.y) {
$scope.filters.company = 'y';
} else {
$scope.filters.company = '';
}
}
};
$scope.both ="z";
$scope.array = [
{name: 'Tobias', lname: 'TLname', company: 'x'},
{name: 'Jeff', lname: 'JLname', company: 'x'},
{name: 'Brian', lname: 'BLname', company: 'x'},
{name: 'Igor', lname: 'ILname', company: 'y'},
{name: 'James', lname: 'JLname', company: 'z'},
{name: 'Brad', lname: 'BLname', company: 'y'},
{name: 'Basil', lname: 'Basil', company: 'z'},
];
});
</script>
</body>
</html>
答案 0 :(得分:0)
您的阵列中没有Field voucher_type,因此无法找到。请添加此字段并使过滤器正常工作。 !
答案 1 :(得分:0)
我做了一些更改,现在工作正常 $scope.valFilter = function (arr) {
return (arr.company == "z" || arr.company == $scope.selectedName);
}
过滤器已更改并添加了新功能
replace = False
谢谢大家