我正在申请' orderby'过滤但不起作用。我从API中获取数据,我仔细检查,确定无疑。但过滤器无效。
<div class="filter-container">
<select class="form-control" ng-model="userOrder">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
<tr class="odd" ng-repeat="user in allusers | filter: query1 | filter: query2 | filter: query3 | filter: query4 | filter: query5 | orderBy: userOrder">
<td>
<span ng-if="user.superuser==1">Yes</span>
<span ng-if="user.superuser==0">No</span>
</td>
<td>
<span ng-if="user.status==0">Not active</span>
<span ng-if="user.status==1">Active</span>
<span ng-if="user.status==-1">Banned</span>
</td>
</tr>
我的控制器:
$scope.user = function () {
$http.get('http://event/users/users/')
.success(function (data) {
$scope.allusers = data;
console.log("all users data coming in user function");
})
.error(function (data) {
console.log('error');
});
};
答案 0 :(得分:0)
按顺序,您需要传递数组元素,就像下面有allusers
一样。那么userOrder
应为name
或lastname
用波纹管改变你的下降并尝试。
<select class="form-control" ng-model="userOrder">
<option value="username">Username</option>
<option value="email">Email</option>
</select>
答案 1 :(得分:0)
我假设您尝试按superuser
对象的user
属性进行排序。
你应该这样做:
orderBy : "superuser"
如果您希望控制选择框是按降序还是按升序排序,请执行以下操作:
<select class="form-control" ng-model="sortReversed">
<option value="False">No</option>
<option value="True">Yes</option>
</select>
...
orderBy : "superuser" : sortReversed
希望有所帮助