我有一个select用作ngtable过滤器的一部分:
<select ng-model="eventsortOrder" >
<option value="All" selected>none</option>
<option value="Active" >Active</option>
<option value="Inactive">Inactive</option>
</select>
表格和过滤器在html中显示如下:
<tr ng-repeat="event in eventcategories.data |filter:eventsortOrder">
<td>{{ event.name }}</td>
<td>{{event.status }} </td>
</tr>
但是数据没有正确过滤..提前谢谢。
答案 0 :(得分:0)
请试试这段代码!!我希望有用......
var app = angular.module('myApp',[]);
app.filter('myfilter',function($filter){
return function( items, filter) {
var filtered = [];
angular.forEach(items, function(item) {
if(filter===null|| filter == item.status || filter == 'All') {
filtered.push(item);
}
});
return filtered;
};
return filtered;
});
app.controller('myController',function($scope){
$scope.eventcategories={
data : [{name:'First',status:"Active"}, {name:'Second',status:"InActive"}]
};
$scope.eventsortOrder=null;
});
&#13;
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
</head>
<body ng-controller="myController">
<select ng-model="query">
<option value="All" selected>none</option>
<option value="Active" >Active</option>
<option value="InActive">Inactive</option>
</select>
<table>
<tr ng-repeat="event in eventcategories.data | myfilter:query">
<td>{{event.name }}</td>
<td>{{event.status}} </td>
</tr>
</table>
</body>
</html>
&#13;