![](/img/trans.png)
[英]Making simple buttons to autoscroll to next and previous Id'd elements
[英]simple Previous/Next buttons
我正在尝试对API的响应进行分页。 该API每页有15个项目。
实际上,我使用的是这样的:
vm.next = function(currentPage){
$http.get('/api?page='+vm.firstPage++)
.then(function(data){
vm.chuck = data.data.Response;
});
}
vm.previous = function(currentPage){
$http.get('/api?page='+vm.firstPage--)
.then(function(data){
vm.chuck = data.data.Response;
});
}
和
vm.firstPage = 1;
我的按钮的html视图:
<div class="text-center">
<button type="button" class="btn btn-warning" ng-click="$ctrl.previous()">Previous</button>
<button type="button" class="btn btn-warning" ng-click="$ctrl.next()">Next</button>
</div>
想法是让每次点击都增加/减少。 它有效,但仅在第二次单击之后。 另外,如果我将vm.firstPage
的值vm.firstPage
为2
,那么自从第一次单击以来就可以使用,但是当我单击Previous时,会变得一团糟。
我该怎么做才能在按钮上增加/减少?
我正在使用AngularJs和javascript
我认为这与运算符的优先级有关。 在调用API之前先创建vm.firstPage ++ / vm.firstPage
vm.next = function(currentPage){
vm.firstPage++;
$http.get('/api?page='+vm.firstPage)
.then(function(data){
vm.chuck = data.data.Response;
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.