【发布时间】:2014-03-24 09:25:21
【问题描述】:
我有一个包含员工所有数据的员工数组。
列表中 1 名员工的示例:
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"
用下面的代码来显示搜索结果。
(只显示名字和照片)
<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>
使用这个 login_controller
var employees; //list of all employees
$scope.data = []; //the filtered employees
$scope.showLimit = 5;
//The filter I made (no input = no results)
$scope.getData = function (query) {
if (query.length === 0) {
$scope.data = [];
} else {
$scope.data = $filter('filter')(employees, query);
}
};
现在我想过滤员工的多个参数(例如用户名和 tla)。当 2 个参数之一等于查询时,它必须在 $scope.data 中(就像 || 一样)。
我想在我的 getData() 函数中执行此操作,以便在给出特定查询输入时进行一些操作。
我在想这样的事情:
$scope.data = $filter('filter')(employees, {'userName': query || 'tla': query});
但这根本行不通。
有什么建议吗?
【问题讨论】:
-
我认为您将不得不编写自己的函数来过滤结果。