我需要从我的控制器访问已在模板(在ng-repeat内)中过滤的数据。
这就是我的意思:
我的模板中有此表:
<table class="table">
<thead>
<th>Name</th>
<th>Gender</th>
</thead>
<tbody>
<tr ng-repeat="person in persons | filter:query">
<td>{{person.name}}</td>
<td>{{person.gender}}</td>
</tr>
</tbody>
</table>
然后我有一个<select>
用于按性别过滤数据的
<h1>Cluster:</h1>
<select ng-model="query.gender" >
<option value ="">ALL</option>
<option value ="male">Male</option>
<option value ="female">Female</option>
</select>
这样可以。
如果有人选择其中一个选项,我需要对过滤后的结果进行处理。这就是为什么我的控制器中有一个$ watch来查找过滤器查询的更改:
$scope.$watch('query.gender', function(newValue, oldValue) {
// Here is where I need to get filtered results
});
我的问题是:
如何从控制器访问FILTERED内容?
我最好这样,而不必在控制器中执行其他“过滤”操作...(由于数据已经被过滤,结果位于内存中的某个地方,对吗?)
我不确定,但是您可以在控制器中使用过滤器功能。因此,尝试类似:
$scope.$watch('query.gender', function(newValue, oldValue) {
var x = $filter('filter')($scope.persons, $scope.query);
});
x应该包含与我认为的表中相同的过滤数据。在这里查看文档:http : //docs.angularjs.org/api/ng.filter : filter了解更多信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句