Angularjs对数组中的不同对象属性进行筛选 “雇员”:[ { “id”:1, “姓名”:“Jhon”, “电话”:“999999999”, “地址”:{ “城市”:“浦那”, “地址1”:“ABC路”, “地址2”:“XYZ大楼”, “邮政编码”:“12455” } } 搜索:

Angularjs对数组中的不同对象属性进行筛选 “雇员”:[ { “id”:1, “姓名”:“Jhon”, “电话”:“999999999”, “地址”:{ “城市”:“浦那”, “地址1”:“ABC路”, “地址2”:“XYZ大楼”, “邮政编码”:“12455” } } 搜索:,angularjs,filter,Angularjs,Filter,如果我们使用相同的查询字符串筛选数组中对象的两个不同属性,则筛选器不起作用。您希望将筛选器逻辑作为函数移出模板并移入控制器,然后在此函数上进行筛选 如果查询与项匹配,或者名称的小写值与查询的小写值匹配,或者城市的小写值与查询的小写值匹配,则函数返回true,否则返回false "Empl": [ { "id": 1, "name": "Jhon", "phone": "9999999999", "address": {

如果我们使用相同的查询字符串筛选数组中对象的两个不同属性,则筛选器不起作用。

您希望将筛选器逻辑作为函数移出模板并移入控制器,然后在此函数上进行筛选

如果查询与项匹配,或者名称的小写值与查询的小写值匹配,或者城市的小写值与查询的小写值匹配,则函数返回true,否则返回false

 "Empl": [
      {
        "id": 1,
        "name": "Jhon",
        "phone": "9999999999",
        "address": {
            "city": "Pune",
            "address_line1": "ABC road",
            "address_line2": "XYZ building",
            "postal_code": "12455"
         }
     }

   Search: <input type="text" ng-model="query"></input>
   <tr ng-repeat="data in Empl | filter : {name:query,
   address:{city:query}}">

$scope.search=函数(项){
如果(!$scope.query |
(item.name.toLowerCase().indexOf($scope.query.toLowerCase())!=-1)|
(item.city.toLowerCase().indexOf($scope.query.toLowerCase())!=-1)
){
返回true;
}
返回false;
};
<tr ng-repeat="data in Empl | filter : search">


$scope.search = function(item) {
    if (!$scope.query || 
        (item.name.toLowerCase().indexOf($scope.query.toLowerCase()) != -1) || 
        (item.city.toLowerCase().indexOf($scope.query.toLowerCase()) != -1)             
       ){
        return true;
    }
    return false;
};