【发布时间】:2015-03-27 01:49:44
【问题描述】:
在 AngularJS 中,我想知道是否可以使用两个可能的值来过滤视图列的数据。所以...如果我将参数值传递给页面的控制器,我想将数据限制为特定值.....
Data:
Product Status
Item 1 Active
Item 2 Planned
Item 3 Completed
Item 4 Cancelled
如果我只想要一个值,我可以传递诸如 filterCol、filterVal 之类的 routeParams,如下所示仅显示处于活动状态的项目:
/programs/status/Active/
app.controller('AllItemsController', function($scope,$http,$rootScope,$routeParams){
$scope.tableFilter = {};
if($routeParams.filterCol && $routeParams.filterVal){
$scope.tableFilter[$routeParams.filterCol] = $routeParams.filterVal;
}
});
我的 XML 类似于:
<table class="table table-bordered table-condensed table-hover" ts-wrapper
<thead>
<tr>
<th ts-criteria="itmName | lowercase">Item Name</th>
<th ts-criteria="status">Status</th>
</tr>
<tr>
<th><input type="text" class="form-control input-sm" ng-model="tableFilter.itmName"></th>
<th><input type="text" class="form-control input-sm" ng-model="tableFilter.status"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="it in allItemData | filter: tableFilter" ts-repeat ">
<td>{{it.itmName}}</td>
<td>{{it.status}}</td>
</tr>
</body>
</table>
现在,如果我想发送诸如“ActPlan”之类的值并显示所有活动或计划中的项目,我该如何更改控制器? (如:/programs/status/ActPlan/)
我想我必须以某种方式更改 $scope.tableFilter 的设置方式(通过检查 $routeParams.filterVal 的值),但我不知道如何设置 tablefilter 并且找不到帮助我的示例.我尝试将其设置为 ['Active, Planned'],但这并没有带来任何问题。
【问题讨论】:
标签: angularjs angularjs-filter