如何用AngularJs的两个字段用相同的select进行过滤?

时间:2017-06-12 09:09:56

标签: javascript html angularjs

我有一个选择框,其中包含一些可过滤的选项。我想过滤两个不同的城市和类别:

HTML:

   <select ng-options="c.id as c.name  for c in categories" class="form-control" name="categories" ng-model="categoriesFilter">
     <option value="">All</option>
   </select>

<select ng-options="o.id as o.name  for o in cities" class="form-control" name="cities" ng-model="citiesFilter">
  <option value="">All</option>
</select>

JS:

$scope.categories = [
    {name : "Private", id : 2},
    {name : "Buisness", id : 1},
    {name : "Deleted", id : 3}
];

我这样过滤:

<tr ng-repeat="cust in customers | filter : {city:citiesFilter|| 
undefined} | filter : {typeCust: categoriesFilter|| undefined} | filter : 
{deleted: categoriesFilter}">

以下是完整示例:jsFiddle

1 个答案:

答案 0 :(得分:0)

您需要链接过滤器

<tr ng-repeat="cust in customers | filter: {city: citiesFilter || undefined} | filter: { typeCust: categoriesFilter || undefined}">

小提琴: https://jsfiddle.net/vaf031mr/16/