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

前端 未结 13 2610
北恋
北恋 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 18:04

    There are a bunch of good solutions here but I'd suggest going the other route with this. If searching is the most important thing and the 'secret' property is not used on the view at all; my approach for this would be to use the built-in angular filter with all its benefits and simply map the model to a new array of objects.

    Example from the question:

    $scope.people = members.map(function(member) { 
                                  return { 
                                    name: member.name, 
                                    phone: member.phone
                                  }});
    

    Now, in html simply use the regular filter to search both these properties.

提交回复
热议问题