如何使$ filter在angularjs中使用OR搜索多个字段

时间:2015-08-20 06:29:29

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

我有一个数据列表说

$scope.data = [
{"id":34,"buyername":"kamaldeep282","status":"NOTRELEASED","statusMessage":"Update Feedback","paymentMethod":"Cash"},
{"id":43,"buyername":"kamaldeep282","status":"RELEASED","statusMessage":"Update Feedback","paymentMethod":"Cash"},
{"id":44,"buyername":"kdsingh1002","status":"RELEASED","statusMessage":"Update Feedback","paymentMethod":"Cash"},
{"id":50,"buyername":"kdsingh1002","status":"RELEASED","statusMessage":"Update Feedback","paymentMethod":"Cash"},
{"id":55,"buyername":"kamaldeep282","status":"DISPUTE","statusMessage":"Dispute Raised","paymentMethod":"Cash"}
];

现在我在HTML中应用了一个过滤器: -

<input type="text" ng-model="querytx" ng-change="filterData()">

并在控制器中将filterData()定义为: -

$scope.filterData = function() {
    $scope.finalData = $filter("filter")($scope.data, { id:$scope.querytx, buyername:$scope.querytx, status:$scope.querytx});
    };

现在$scope.finalData中的filterData返回的是id, buyername的AND和状态。 <{1}}中有iff $scope.querytx,只返回该行。

我想要的是ID,买方名称和状态,或者如果{,1}}在id,buyername和status中都有,那么应该返回该行。

注意:

  • 我不想在所有领域进行搜索。
  • 如图所示,无法在HTML id, buyername and status,中执行此类操作 在我正在使用的链接https://stackoverflow.com/a/20850929/4948805中 角度表中的$scope.querytx自动重复。

0 个答案:

没有答案