我在使用orderBy
AngularJS 中的过滤器时遇到问题。这是我的设置:
<li ng-repeat="item in listItems.data | orderBy:order">
<a ng-click="getRelated(item._id)">{{ item.title }}</a>
</li>
控制器部分:
$scope.order = 'year';
$scope.listItems = $http.post($scope.url, {'filterType': 'abc', 'letter': $scope.params.letter});
$scope.setOrder = function(order) {
$scope.order = order;
}
最后是我想用来订购数据的“开关”
<span class="sort--title">Sort by</span>
<a ng-class="{true:'selected', false:''}[order=='title']" href="" ng-click="setOrder('title')" class="sort--attribute">Title</a>
<a ng-class="{true:'selected', false:''}[order=='year']" href="" ng-click="setOrder('year')" class="sort--attribute">Year</a>
<a ng-class="{true:'selected', false:''}[order=='length']" href="" ng-click="setOrder('length')" class="sort--attribute">Length</a>
<a ng-class="{true:'selected', false:''}[order=='date_added']" href="" ng-click="setOrder('date_added')" class="sort--attribute">Date Added</a>
当我单击按钮时,列表不会重新排序。
当我手动更改初始$scope.order
值时,列表按属性排序。也ng-class
正确更新。我显然错过了一些东西!