Filtering by Multiple Specific Model Properties in AngularJS (in OR relationship)

前端 未结 13 2549
北恋
北恋 2020-11-22 17:08

Take a look at the example here: http://docs.angularjs.org/api/ng.filter:filter

You can search by any of the phone properties by using

13条回答
  •  长发绾君心
    2020-11-22 17:58

    Here's simple solution for those who want a quick filter against an object:

    
    

    The array filter lets you mimic the object you are trying to filter. In the above case, the following classes would work just fine:

    var card = function(name, type) {
      var _name = name;
      var _type = type;
    
      return {
        Name: _name,
        Type: _type
      };
    };
    

    And where the deck might look like:

    var deck = function() {
      var _cards = [new card('Jack', 'Face'),
                    new card('7', 'Numeral')];
    
      return {
        Cards: _cards
      };
    };
    

    And if you want to filter multiple properties of the object just separate field names by a comma:

    
    

    EDIT: Here's a working plnkr that provides an example of single and multiple property filters:

    http://embed.plnkr.co/i0wCx6l1WPYljk57SXzV/

提交回复
热议问题