2 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
app.controller('BusinessCtrl', ['$scope', '$rootScope', 'BusinessService', function ($scope, $rootScope, BusinessService) {
$rootScope.title = '流水列表';
$scope.currentPage = 1;
$scope.totalPage = 1;
$scope.pageSize = 40;
$scope.pages = [];
$scope.endPage = 1;
//獲取總流水
BusinessService.total().success(function (data) {
$scope.total = data;
});
$scope.load = function () {
BusinessService.list($scope.currentPage, $scope.pageSize).success(function (data) {
$scope.items = data.list;
//獲取總頁數(shù)
$scope.totalPage = Math.ceil(data.count / $scope.pageSize);
$scope.endPage = $scope.totalPage;
//生成數(shù)字鏈接
if ($scope.currentPage > 1 && $scope.currentPage < $scope.totalPage) {
$scope.pages = [
$scope.currentPage - 1,
$scope.currentPage,
$scope.currentPage + 1
];
} else if ($scope.currentPage == 1 && $scope.totalPage > 1) {
$scope.pages = [
$scope.currentPage,
$scope.currentPage + 1
];
} else if ($scope.currentPage == $scope.totalPage && $scope.totalPage > 1) {
$scope.pages = [
$scope.currentPage - 1,
$scope.currentPage
];
}
});
};
$scope.next = function () {
if ($scope.currentPage < $scope.totalPage) {
$scope.currentPage++;
$scope.load();
}
};
$scope.prev = function () {
if ($scope.currentPage > 1) {
$scope.currentPage--;
$scope.load();
}
};
$scope.loadPage = function (page) {
$scope.currentPage = page;
$scope.load();
};
}]);

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊
用pagination。
<divpagination total-items="totalItems" page="currentPage" first-text="首頁"
last-text="尾頁" ng-model="currentPage" items-per-page="{{pagesize}}" previous-text="上一頁"
next-text='下一頁' max-size="maxSize" ng-change="pageChanged()" class="pagination-sm"
boundary-links="true"></div>
在控制器里定義totalItems、currentPage、pagesize、maxSize和pageChanged()事件。
- 2 回答
- 0 關(guān)注
- 661 瀏覽
添加回答
舉報(bào)