使用ng-repeat过滤某些列

时间:2015-02-26 10:25:16

标签: angularjs angularjs-ng-repeat

我尝试使用特定键上的ng-repeat过滤对象数组,或者甚至可以将其称为列。 应用过滤器的键/列来自选择框。

data-ng-model="selectedValue" // -> item.name

应搜索的术语来自输入字段,并按以下方式进行十进制:

<input type="text" data-ng-model="q">

<div data-ng-repeat="item in items |filter:{selectBoxValue:q}">{{item.name}}</div> 

遗憾的是,上述情况并不奏效。 但是当我在我的过滤器中使用selectBoxValue的item.name instat时,效果很好。

2 个答案:

答案 0 :(得分:0)

找到解决方案。 现在,您可以过滤特定列,以防anyProperty。

<input type="button" ng-click="changeFilter('anyProperty')">
<input type="text" ng-model="q[filter]">
<div ng-repeat="item in items | filter:q">

$scope.changeFilter = function(q){
   $scope.filter = q;
}

答案 1 :(得分:0)

在你的控制器中:
$ scope.search = {}

在您的标记中

<input ng-model="colName"> //colName <input ng-model="search[colName]"> //colvalue

<div data-ng-repeat="item in items |filter:search">{{item.name}}</div>

相关问题