Javascript ng使用Limito过滤器重复第一页和最后一页
在这里使用angularjs 1.3: 我在我的表格行中使用limit to,如下例所示:Javascript ng使用Limito过滤器重复第一页和最后一页,javascript,angularjs,Javascript,Angularjs,在这里使用angularjs 1.3: 我在我的表格行中使用limit to,如下例所示: <tr ng-repeat="r in table.rows | dataLimitTo:limit:start"> <td>{{r.id}}</td> <td>{{r.name}}</td> </tr> <div class="form-group" ng-if="table.rows.length>10
<tr ng-repeat="r in table.rows | dataLimitTo:limit:start">
<td>{{r.id}}</td>
<td>{{r.name}}</td>
</tr>
<div class="form-group" ng-if="table.rows.length>100">
<button class="btn btn-primary" type="button" ng-click="prev()">Prev</button>
<button class="btn btn-primary " type="button" ng-click="next()">Next</button>
</div>
在我的控制器中:
$scope.start = 0;
$scope.limit = 100;
$scope.next = function () {
incrementLimit(true)
}
$scope.prev = function () {
incrementLimit(false)
}
function incrementLimit(up) {
if (up) {
($scope.start <= ($scope.table.rows.length - $scope.limit)) ? $scope.start += 100 : $scope.start = 0;
} else {
$scope.start > 100 ? $scope.start -= 100 : $scope.start = 0;
}
}
$scope.start=0;
$scope.limit=100;
$scope.next=函数(){
增量限制(真)
}
$scope.prev=函数(){
增量限制(false)
}
函数增量限制(向上){
如果(向上){
($scope.start 100?$scope.start-=100:$scope.start=0;
}
}
以上代码运行良好,我能够使用prev和next按钮移动黑白页面
我还想为第一页和最后一页设置两个按钮。如果他们按下第一页按钮,他们将返回并看到第一页的行,如果他们单击最后一页按钮,他们将看到第页的行
我上面的代码是否可行?我需要做哪些更改
很抱歉,目前我没有寻找任何其他第三方解决方案。要移动到第一页,请将start设置为零,即
$scope.start=0
我可以将最后一页作为:
$scope.start = Math.floor($scope.table.rows.length / $scope.limit) * 100;
应该是:
$scope.start = Math.floor($scope.table.rows.length / $scope.limit) * $scope.limit;
或者:
$scope.start = lastPageStart($scope.table.rows.length, $scope.limit)
function lastPageStart (len, limit) {
return len - (len % limit);
}
@georgeawg抱歉,这只是一个示例,所以我一定是匆忙编写的。如上所述,我在数据绑定和跨页面移动方面没有问题。我不确定如何移动到最后一页和第一页。无论如何,我已经更新了代码并删除了ng模型部分。要移动到第一页,请将start设置为零,即
$scope.start=0
。要移动到最后一页,请计算适当的start值。这有多难?您有什么问题?start工作正常。我可以按以下方式完成最后一页:$scope.start=Math.floor($scope.table.rows.length/$scope.limit)*100;
$scope.start = lastPageStart($scope.table.rows.length, $scope.limit)
function lastPageStart (len, limit) {
return len - (len % limit);
}