我有一个数据列表说
$scope.data = [
{"id":1,"buyername":"kamaldeep282","status":"kdsingh1002","user":"Hitesh"},
{"id":2,"buyername":"kamaldeep282","status":"RELEASED","user":"kdsingh1002"},
{"id":3,"buyername":"kamaldeep282","status":"RELEASED","user":"Hitesh"},
{"id":4,"buyername":"kdsingh1002","status":"RELEASED","user":"Hitesh"},
{"id":5,"buyername":"kamaldeep282","status":"DISPUTE","user":"kdsingh1002"}
];
现在我在HTML中应用了一个过滤器: -
<input type="text" ng-model="searchText" ng-change="filterData()">
并在控制器中将filterData()定义为: -
$scope.filterData = function() {
$scope.finalData = $filter("filter")($scope.data, { buyername:$scope.searchText, status:$scope.searchText });
};
现在我想要的是买家名称,状态,即在searchText,如果我输入&#39; kdsingh1002&#39;那么这些行应该返回: - {&#34; ID&#34;:1,&#34; BUYERNAME&#34;:&#34; kamaldeep282&#34;&#34;状态&#34;:&#34; kdsingh1002&#34;&# 34;用户&#34;:&#34;亚太区首席技术官Matt&#34;}, {&#34; ID&#34:4,&#34; BUYERNAME&#34;:&#34; kdsingh1002&#34;&#34;状态&#34;:&#34; RELEASED&#34;&# 34;用户&#34;:&#34;亚太区首席技术官Matt&#34;},
注意: 我不想在所有领域进行搜索。
答案 0 :(得分:0)
不确定$filter
的OR情况,但您可以使用angular.forEach
来过滤记录。
filterData 功能:
$scope.filterData = function() {
$scope.finalData = [];
angular.forEach($scope.data,function(data){
if(data.status.indexOf($scope.searchText) > -1 || data.buyername.indexOf($scope.searchText) > -1){
$scope.finalData.push(data);
}
})
};