angularjs filter not filter multipe filter value

夙愿已清 提交于 2019-12-12 05:48:46

问题


Am looking for angularjs multiple condition filter like this arr in array | filter:filters.search | filter:{company: selectedName} | filter:{voucher_type: both } It working but not filtering all condition am pasting my full code here . filter:{company: selectedName} | filter:{voucher_type: both } this filter step is wrong in my code.@Thank you for response

<html >
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<title>search</title>
</head>
<body>
<div ng-app="app" ng-controller="mainCtrl">

 <div><select ng-model="selectedName" ng-options="x for x in names">
</select>
    </div>
    <input type="text" ng-model="both">
       <div>Search by Name: <input type="text" ng-model="filters.search"></div>

       <div ng-repeat="arr in array | filter:filters.search | filter:{company: selectedName} | filter:{voucher_type: both } ">
           <span ng-bind="arr.name"></span>    
       </div>

</div>

<script type="text/javascript" src="js/angular.min.js"></script> 
<script src="js/ui-bootstrap-tpls-0.9.0.js"></script> 
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('mainCtrl', function($scope) {

$scope.names = ["x", "y"];
      $scope.filters = {
        x: false,
        company: '',
        search: ''
    };

       $scope.actions = {
        updateyCompany: function () {
            if($scope.filters.y) {
                $scope.filters.company = 'y';
            } else {
                 $scope.filters.company = '';   
            }
        }
    };

    $scope.both ="z";

    $scope.array = [
    {name: 'Tobias', lname: 'TLname', company: 'x'},
    {name: 'Jeff', lname: 'JLname', company: 'x'},
    {name: 'Brian', lname: 'BLname', company: 'x'},
    {name: 'Igor', lname: 'ILname', company: 'y'},
    {name: 'James', lname: 'JLname', company: 'z'},
    {name: 'Brad', lname: 'BLname', company: 'y'},
    {name: 'Basil', lname: 'Basil', company: 'z'},
  ];
});
</script>


</body>
</html> 

回答1:


Field voucher_type is not available in your array so, it can not find out. Please add this field and make filter working Properly. !!!




回答2:


am make some changes it work fine now filter:valFilter filter is changed and new function is added

 $scope.valFilter = function (arr) {
    return (arr.company == "z" || arr.company == $scope.selectedName);
    }

Thank you all



来源:https://stackoverflow.com/questions/39244804/angularjs-filter-not-filter-multipe-filter-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!