search

Home  >  Q&A  >  body text

angular.js - angular filters data display of specified status


As shown in Figure 1, there are many, many data in a table,
Among them, the status is the following four:
1) 'issued': 'Published ',
2)'deleted': 'Deleted',
3)'reported': 'Reported',
4) 'masked': 'Blocked'

Tried<tr ng-repeat="post in filterPostList | filter:'status':'issued'||'masked'">
This way only the issued data can be displayed.
Now I want to display the data of issued and masked, what should I do?

天蓬老师天蓬老师2836 days ago830

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-05-15 17:13:42

    Write a custom filter

    app.filter("statusFilter",function(){
        return function(input,uppercase){
            var out = [];
            for(var i=0 ; i<input.length; i++){
                if(input[i].status=='issued'||input[i].status=='masked'){
                    out.push(input[i]);
                }
            }
            return out;
        }
    });

    HTML:

    <tr ng-repeat="post in filterPostList | statusFilter>

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 17:13:42

    No need to write filters

    Just write a function

    
    $scope.statusFilter = function(item){
        return item.status == 'issued' || item.status == 'masked';
    }
    
    <tr ng-repeat="post in filterPostList | filter: statusFilter">
    

    Suddenly realized that I answered a question with a long history. . . .

    reply
    0
  • 某草草

    某草草2017-05-15 17:13:42

    Another way of thinking. No need to write filters or functions.

    reply
    0
  • Cancelreply