是否可以过滤对象数组,以便属性值可以是几个值(OR条件),而无需编写自定义过滤器
这类似于这个问题 - Angular.js ng-repeat:按单个字段过滤
而不是
<div ng-repeat="product in products | filter: { color: 'red' }">
Run Code Online (Sandbox Code Playgroud)
有可能做这样的事情
<div ng-repeat="product in products | filter: { color: 'red'||'blue' }">
Run Code Online (Sandbox Code Playgroud)
如下样本数据─
$scope.products = [
{ id: 1, name: 'test', color: 'red' },
{ id: 2, name: 'bob', color: 'blue' }
/*... etc... */
];
Run Code Online (Sandbox Code Playgroud)
我没试过
<div ng-repeat="product in products | filter: { color: ('red'||'blue') }">
Run Code Online (Sandbox Code Playgroud) 我有像这样的角度嵌套对象.有没有办法过滤它的嵌套属性
<li ng-repeat="shop in shops | filter:search">
search.locations.city_id = 22
Run Code Online (Sandbox Code Playgroud)
我只显示父元素,但想要同时过滤它们,例如:
search =
category_id: 2
locations:
city_id: 368
[
name: "xxx"
category_id: 1
locations: [
city_id: 368
region_id: 4
,
city_id: 368
region_id: 4
,
city_id: 368
region_id: 4
]
,
name: "xxx"
category_id: 2
locations: [
city_id: 30
region_id: 4
,
city_id: 22
region_id: 2
]
]
Run Code Online (Sandbox Code Playgroud) 我试图通过特定的数组属性过滤ngRepeat.
JS:
app.controller('UserIndexController', function ($scope, $http, $window) {
$scope.search = {};
$http({ method: 'GET', url: '/api/v2/group' })
.success(function(data, status, headers, config) {
$scope.groups = data;
})
.error(function(data, status, headers, config) {
});
$http({ method: 'GET', url: '/api/v2/user' })
.success(function(data, status, headers, config) {
$scope.users = data;
})
.error(function(data, status, headers, config) {
});
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div data-ng-controller="UserIndexController">
<select
ng-model="search.group"
ng-options="group.name as group.name for group in groups"
class="form-control">
<option value="">Filter Users by Group</option>
</select>
<table class="table table-responsive table-striped table-hover">
<thead>
<tr> …Run Code Online (Sandbox Code Playgroud)