angularjs實現分頁查詢功能的實例代碼,具體代碼如下所示:
//首頁導入<script type="text/javascript" src="framework/tm.pagination.js"></script> //routerApp中注入'tm.pagination' //html頁面上<tm-pagination conf="paginationConf"></tm-pagination> //controller.js代碼 var reSearch = function() { var postData = { //發送給后臺的請求數據 currentPage: $scope.paginationConf.currentPage, pageSize: $scope.paginationConf.itemsPerPage, pickup: $scope.pickups, startTime: $scope.startTime, endTime: $scope.endTime, minMoney: $scope.minMoney, maxMoney: $scope.maxMoney }; $http.post('后臺分頁接口', postData).success(function(response) { $scope.paginationConf.totalItems = response.totalElements; //總條數 $scope.takeGoodsLists = response.content; //具體內容 //共享的數據賦值 }); } $scope.reSearch = reSearch; //配置分頁基本參數 $scope.paginationConf = { currentPage: 1, //起始頁 //totalItems:300,//總共有多少條記錄 itemsPerPage: 5, // 每頁展示的數據條數 //pagesLength:5,//分頁條目的長度 perPageOptions: [5, 10, 20] //可選擇顯示條數的數組 }; //當頁碼和頁面記錄數發生變化時監控后臺查詢如果把currentPage和itemsPerPage分開監控的話則會觸發兩次后臺事件。 $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', reSearch); 新聞熱點
疑難解答