简体   繁体   中英

Filter ng-repeat on Angularjs,

Im having trouble with a filter i have something like this:

<tr ng-repeat="data in dataset | filter:{id:12}">       
    <td>{{data.id}}</td>
    <td>{{data.name}}</td>
</tr>

i would to be able to filter by an array of ids something like this

id=[12,14,23]

and show the rows that have those ids

thanks for any help

<tr ng-repeat="data in dataset | filter:filterFunction">       
    <td>{{data.id}}</td>
    <td>{{data.name}}</td>
</tr>

Controller:

$scope.filterFunction = function(data) {
  return $scope.filterValues.indexOf(data.id) !== -1 ? true : false;
};

$scope.filterValues = [12, 14, 23];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM