angularjs - How to filter an object array with multiple parameters? -


i'm having array employees containing data of employees.

example of 1 employee in list:

accountactive: false companynr: 0 email: "aart.versendaal@technomanage.nl" id: 100 photourl: "http://technet/employeephoto/anonymous.jpg" staffnr: 0 tla: "fis" username: "firstname surname" workplace: "999" 

with following code show search results.
(only show name , photo)

<div class="result" ng-repeat="employee in data | limitto:showlimit">     <div class="result_wrapper">         <div class="result_name">{{employee.username}}</div>         <div class="result_image">             <img ng-src="{{employee.photourl}}"/>         </div>     </div> </div> 

with login_controller

var employees; //list of employees $scope.data = []; //the filtered employees $scope.showlimit = 5;  //the filter made (no input = no results) $scope.getdata = function (query) {     if (query.length === 0) {         $scope.data = [];     } else {         $scope.data = $filter('filter')(employees, query);     } }; 

now want filter on multiple params of employee (e.g. username , tla). when 1 of 2 params equal query, must in $scope.data (just || ).
want in getdata() function can manipulate things when certen query input given.

i thinking like:

$scope.data = $filter('filter')(employees, {'username': query || 'tla': query}); 

but wont work.
suggestions?

thanks jason goemaat pointing me out in direction had go

controller:

var employees; //list of employees $scope.data = []; //the filtered employees $scope.showlimit = 5;  //the filter made (no input = no results) $scope.getdata = function (query) {     if (query.length === 0) {         $scope.data = [];     } else {         $scope.data = $filter('employeelogin')(employees, query);     } }; 

filter:

app.module.filter('employeelogin', function () {     return function (employees, query) {         var results = [];         var q = query.tolowercase();         angular.foreach(employees, function (employee) {             if (employee.username.tolowercase().indexof(q) !== -1) {                 results.push(employee);             } else if (employee.tla.tolowercase().indexof(q) !== -1) {                 results.push(employee);             }         });         return results;     }; }); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -