How to create a composite filter with two way binding?

后端 未结 2 841
清酒与你
清酒与你 2021-01-21 11:33

I want to display a list of items in a table and allow users to filter the items using form controls.

My Problem
I am able to accomplish this when t

相关标签:
2条回答
  • 2021-01-21 11:59

    angular can automatically two-way-bind everything for you without the need for filters:

    JS:

    $scope.filteredRecords = function() {
      return $scope.records.filter(function(record, i) {
        return record.travelerCount === $scope.travelerFilter &&
          record.group === $scope.groupFilter;
      });
    }
    

    HTML:

    <tr ng-repeat="record in filteredRecords()">
    

    See here for a live example: http://plnkr.co/edit/aeBv2soGG06Trpp9WI4f?p=preview

    0 讨论(0)
  • 2021-01-21 12:17

    You can specify the filter as part of the ng-repeat, i.e.:

    <tr ng-repeat="record in records | filter:{group:groupFilter} | filter:{travelerCount:travelerFilter}">
    

    See here for a live version: http://plnkr.co/edit/1UcGDpwUAbtvEhUyCFss?p=preview

    0 讨论(0)
提交回复
热议问题