AngularJS ng-repeat:orderBy 不对 limitTo 变化做出反应,仅适用于旧数据
AngularJS ng-repeat : orderBy not react on limitTo changes, works with old data only
我有一个 ng-repeat,前 20 个项目通过 limitTo 及其动态 - 我按 "read more" +20 变得可见。
问题:我有 orderBy,在 "read more" 之后它只对旧数据进行排序...
我该如何解决?
-- 控制器 --
$scope.items = [{"id":38,"updated_at":"02.05.2016"}, ... ];
$scope.showMore = function(){
$scope.form.page_size += 20;
};
$scope.sortBy = function (propertyName) {
$scope.propertyName = propertyName;
$scope.reverse = (propertyName !== null && $scope.propertyName === propertyName) ? !$scope.reverse : false;
};
--html--
<table>
<thead>
<tr>
<th ng-click="sortBy('updated_at')">Updated</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(index, entry) in items | limitTo:form.page_size | orderBy:propertyName:reverse track by entry.id">
...
</tr>
</tbody>
</table>
<button type="button" ng-click="showMore()">Show More</button>
最后把limitTo
放在ng-repeat
表达式中,如下所示:
<tr ng-repeat="(index, entry) in items | orderBy:propertyName:reverse track by entry.id
| limitTo:form.page_size">
...
</tr>
我有一个 ng-repeat,前 20 个项目通过 limitTo 及其动态 - 我按 "read more" +20 变得可见。
问题:我有 orderBy,在 "read more" 之后它只对旧数据进行排序...
我该如何解决?
-- 控制器 --
$scope.items = [{"id":38,"updated_at":"02.05.2016"}, ... ];
$scope.showMore = function(){
$scope.form.page_size += 20;
};
$scope.sortBy = function (propertyName) {
$scope.propertyName = propertyName;
$scope.reverse = (propertyName !== null && $scope.propertyName === propertyName) ? !$scope.reverse : false;
};
--html--
<table>
<thead>
<tr>
<th ng-click="sortBy('updated_at')">Updated</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(index, entry) in items | limitTo:form.page_size | orderBy:propertyName:reverse track by entry.id">
...
</tr>
</tbody>
</table>
<button type="button" ng-click="showMore()">Show More</button>
最后把limitTo
放在ng-repeat
表达式中,如下所示:
<tr ng-repeat="(index, entry) in items | orderBy:propertyName:reverse track by entry.id
| limitTo:form.page_size">
...
</tr>