问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

angular.js翻页怎么写

发布网友 发布时间:2022-04-21 02:10

我来回答

3个回答

懂视网 时间:2022-05-16 04:27

html:

<pagination 
total-items= 
ng-model= 
items-per-page= 
previous-text= 
next-text= 
page-sizes= 
edit-page= 
ng-change=> //获取数据的方法
</pagination>

js:数据取多次 每次翻页都重新取数据

$scope.currentPage = = = [,, , , = ==($scope.currentPage>&&! =: $scope.currentPage-=, angular.toJson(=== Math.ceil($scope.totalItems /=

js:分页情况:数据只取一次

// 分页情况:数据只取一次
 ($scope.getData = function (currentPage, itemPerPage) {if (angular.isUndefined($scope.dataList)) {var params = {'pageIndex': currentPage,'pageSize': itemPerPage,'insuranceOrgCode': $scope.insuranceOrgCode,'prodType': $scope.prodType,'productName': $scope.productName,
  };
  $http.post('/product/getProductList.do', params).success(function (res) {

   $scope.dataList = res.data.listObj;

   $scope.totalItems = ($scope.dataListStore = res.data.listObj).length;

   $scope.pageCount = Math.ceil($scope.totalItems / itemPerPage);

   $scope.getData(currentPage, itemPerPage)
  })
  } else {var start = itemPerPage * (currentPage - 1);var end = ($scope.totalItems < itemPerPage * currentPage) ? $scope.totalItems : itemPerPage * currentPage;
  $scope.dataList = ($scope.dataListStore.slice(start, end));
  }
 })($scope.currentPage = 1, $scope.itemPerPage = 2, $scope.pageSizes = [2,10, 20, 50, 100], $scope.editPage = true);

以下是引入的分页插件文件

/*
 * angular-ui-bootstrap
 * http://angular-ui.github.io/bootstrap/

 * Version: 0.12.1 - 2015-10-17
 * License: MIT
 * ReWrite Ver:1.0.1
 * Fixed:页数只能输入数字
 *
 * ReWrite Ver:1.0.2
 * Fixed:页数计算优化 *///angular.module("ui.bootstrap", ["ui.bootstrap.tpls","ui.bootstrap.pagination"]);//angular.module("ui.bootstrap.tpls", ["template/pagination/pager.html","template/pagination/pagination.html"]);angular.module('ui.bootstrap.pagination', ["template/pagination/pager.html","template/pagination/pagination.html"])

 .controller('PaginationController', ['$scope', '$attrs', '$parse', function ($scope, $attrs, $parse) {
 $scope.pageSizes =[2,10, 20, 50, 100, 300, 500]; var self = this,
  ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl setNumPages = $attrs.numPages ? $parse($attrs.numPages).assign : angular.noop; this.init = function(ngModelCtrl_, config) {
 ngModelCtrl = ngModelCtrl_;this.config = config;

 ngModelCtrl.$render = function() {
  self.render();
 };if ($attrs.itemsPerPage) {
  $scope.$parent.$watch($parse($attrs.itemsPerPage), function(n,o) {if(n) {
  self.itemsPerPage = parseInt(n, 10);
  $scope.itemPerPage = parseInt(n, 10);
  $scope.totalPages = self.calculateTotalPages();
  }
  });
 } else {  this.itemsPerPage = config.itemsPerPage;
 }
 }; this.calculateTotalPages = function() {var totalPages = this.itemsPerPage < 1 ? 1 : Math.ceil($scope.totalItems / this.itemsPerPage);return Math.max(totalPages || 0, 1);
 }; this.render = function() {if(ngModelCtrl.$viewValue!='')
  $scope.page = parseInt(ngModelCtrl.$viewValue, 10) || 1;
 };

 $scope.selectPage = function(page) {
 console.log('page:',page)if (/^[0-9]+$/.test(page)) {  if ($scope.page !== page && page > 0 && page <= $scope.totalPages) {
  ngModelCtrl.$setViewValue(page);
  ngModelCtrl.$render();
  }  if(page==1){
  setTimeout(function () {
   $("#paginationNum").focus();
   $("#paginationNum").select();
  })
  }
 }else {
  $scope.selectPage($scope.currentPage='1');

 }
 };


 $scope.getText = function( key ) {return $scope[key + 'Text'] || self.config[key + 'Text'];
 };
 $scope.noPrevious = function() {return $scope.page === 1;
 };
 $scope.noNext = function() {return $scope.page === $scope.totalPages;
 };

 $scope.$watch('totalItems', function() {
 $scope.totalPages = self.calculateTotalPages();
 });
 $scope.$watch('totalPages', function(value) {
 setNumPages($scope.$parent, value); // Readonly variableif ( $scope.page > value ) {
  $scope.selectPage(value);
 } else {
  ngModelCtrl.$render();
 }
 });

 $scope.checkPage=function(min,max,c) {var current = c;if (typeof current != 'string' || current.length > 0){
  current = current < min ? min : current > max ? max : current;
 }return current;
 };// $scope.keyDown = function (page) {// var oEvent = window.event;// if (oEvent.keyCode == 8 && page == 1) {//  $("#paginationNum").focus();//  $("#paginationNum").select();// }// };//window.keyDown = function () {var oEvent = window.event;if (oEvent.keyCode == 8 && $scope.currentPage == 1) {
  $("#paginationNum").focus();
  $("#paginationNum").select();
  }
 }

 }])

 .constant('paginationConfig', {
 itemsPerPage: 10,
 boundaryLinks: false,
 directionLinks: true,
 firstText: 'First',
 previousText: 'Previous',
 nextText: 'Next',
 lastText: 'Last',
 rotate: true})

 .directive('pagination', ['$parse', 'paginationConfig', function($parse, paginationConfig) { return {
 restrict: 'EA',
 scope: {
  totalItems: '=',
  itemsPerPage:'=',
  pageSizes:'=',
  editPage:'=',
  firstText: '@',
  previousText: '@',
  nextText: '@',
  lastText: '@',
  currentPage:'=ngModel'},
 require: ['pagination', '?ngModel'],
 controller: 'PaginationController',
 templateUrl: 'template/pagination/pagination.html',
 replace: true,
 link: function(scope, element, attrs, ctrls) {  var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];  if (!ngModelCtrl) {return; // do nothing if no ng-model  }
  scope.$watch('itemsPerPage',function(n,o){if(n&&n!=o) {
  ngModelCtrl.$setViewValue(0);
  ngModelCtrl.$setViewValue(1);
  ngModelCtrl.$render();
  }
  })  // Setup configuration parameters var maxSize = angular.isDefined(attrs.maxSize) ? scope.$parent.$eval(attrs.maxSize) : paginationConfig.maxSize,
  rotate = angular.isDefined(attrs.rotate) ? scope.$parent.$eval(attrs.rotate) : paginationConfig.rotate;
  scope.boundaryLinks = angular.isDefined(attrs.boundaryLinks) ? scope.$parent.$eval(attrs.boundaryLinks) : paginationConfig.boundaryLinks;
  scope.directionLinks = angular.isDefined(attrs.directionLinks) ? scope.$parent.$eval(attrs.directionLinks) : paginationConfig.directionLinks;

  paginationCtrl.init(ngModelCtrl, paginationConfig);  if (attrs.maxSize) {
  scope.$parent.$watch($parse(attrs.maxSize), function(value) {
  maxSize = parseInt(value, 10);
  paginationCtrl.render();
  });
  }  // Create page object used in template  function makePage(number, text, isActive) {return {
  number: number,
  text: text,
  active: isActive
  };
  }

  function getPages(currentPage, totalPages) {var pages = [];// Default page limitsvar startPage = 1, endPage = totalPages;var isMaxSized = ( angular.isDefined(maxSize) && maxSize < totalPages );// recompute if maxSizeif ( isMaxSized ) {  if ( rotate ) {// Current page is displayed in the middle of the visible onesstartPage = Math.max(currentPage - Math.floor(maxSize/2), 1);
  endPage = startPage + maxSize - 1;// Adjust if limit is exceededif (endPage > totalPages) {
   endPage = totalPages;
   startPage = endPage - maxSize + 1;
  }
  } else {// Visible pages are paginated with maxSizestartPage = ((Math.ceil(currentPage / maxSize) - 1) * maxSize) + 1;// Adjust last page if limit is exceededendPage = Math.min(startPage + maxSize - 1, totalPages);
  }
  }// Add page number linksfor (var number = startPage; number <= endPage; number++) {  //ignore those unused numbers if(number == startPage||number == endPage || number < currentPage+10&&number > currentPage-10) {var page = makePage(number, number, number === currentPage);
  pages.push(page);
  }
  }// Add links to move between page setsif ( isMaxSized && ! rotate ) {  if ( startPage > 1 ) {var previousPageSet = makePage(startPage - 1, '...', false);
  pages.unshift(previousPageSet);
  }  if ( endPage < totalPages ) {var nextPageSet = makePage(endPage + 1, '...', false);
  pages.push(nextPageSet);
  }
  }return pages;
  }  var originalRender = paginationCtrl.render;
  paginationCtrl.render = function() {
  originalRender();if (scope.page > 0 && scope.page <= scope.totalPages) {
  scope.pages = getPages(scope.page, scope.totalPages);
  }
  };
 }
 };
 }])

 .constant('pagerConfig', {
 itemsPerPage: 10,
 previousText: '? Previous',
 nextText: 'Next ?',
 align: true})

 .directive('pager', ['pagerConfig', function(pagerConfig) { return {
 restrict: 'EA',
 scope: {
  totalItems: '=',
  previousText: '@',
  nextText: '@'},
 require: ['pager', '?ngModel'],
 controller: 'PaginationController',
 templateUrl: 'template/pagination/pager.html',
 replace: true,
 link: function(scope, element, attrs, ctrls) {  var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];  if (!ngModelCtrl) {return; // do nothing if no ng-model  }

  scope.align = angular.isDefined(attrs.align) ? scope.$parent.$eval(attrs.align) : pagerConfig.align;
  paginationCtrl.init(ngModelCtrl, pagerConfig);
 }
 };
 }]);

angular.module("template/pagination/pager.html", []).run(["$templateCache", function($templateCache) {
 $templateCache.put("template/pagination/pager.html", "<ul class="pager">
" + " <li ng-class="{disabled: noPrevious(), previous: align}"><a href ng-click="selectPage(page - 1)">{{getText('previous')}}</a></li>
" + " <li ng-class="{disabled: noNext(), next: align}"><a href ng-click="selectPage(page + 1)">{{getText('next')}}</a></li>
" + "</ul>");
}]);// angular.module("template/pagination/pagination.html", []).run(["$templateCache", function($templateCache) {// $templateCache.put("template/pagination/pagination.html",// "<div>
"+// "<div class="edit"><span class="total-page" ng-show="editPage"> 共{{totalPages}}页  共{{totalItems}}条  </span><span class="page-edit" ng-show="editPage">第 "+// "<input type="text" ng-model="currentPage" ng-change="selectPage(currentPage=checkPage(1,totalPages,currentPage))""+// "requied class="table-counts-text"/> 页</span><span class="page-size-edit" ng-show="pageSizes">  每页 
"+// "<select ng-model="itemsPerPage" class="table-counts-select"
"+// "ng-options="count as count for count in pageSizes">
"+// "</select> 条</span>
"+// "</div>
"+// "<ul class="pagination">
" +// " <li ng-if="boundaryLinks" ng-class="{disabled: noPrevious()}"><a href ng-click="selectPage(1)">{{getText('first')}}</a></li>
" +// " <li ng-if="directionLinks" ng-class="{disabled: noPrevious()}"><a href ng-click="selectPage(page - 1)">{{getText('previous')}}</a></li>
" +// " <li ng-if="page.number==1||page.number==totalPages||(page.number-currentPage)*(page.number-currentPage)<=16" "+// "ng-repeat="page in pages track by $index" ng-class="{active: page.active}">"+// "<a ng-if="page.number==1||page.number==totalPages||(page.number-currentPage)*(page.number-currentPage)<16" href ng-click="selectPage(page.number)">{{page.text}}</a>"+// "<span ng-if="page.number!=1&&page.number!=totalPages&&(page.number-currentPage)*(page.number-currentPage)==16">....</span></li>
" +// " <li ng-if="directionLinks" ng-class="{disabled: noNext()}"><a href ng-click="selectPage(page + 1)">{{getText('next')}}</a></li>
" +// " <li ng-if="boundaryLinks" ng-class="{disabled: noNext()}"><a href ng-click="selectPage(totalPages)">{{getText('last')}}</a></li>
" +// "</ul></div>");// }]);angular.module("template/pagination/pagination.html", []).run(["$templateCache", function($templateCache) {
 $templateCache.put("template/pagination/pagination.html", "<div class='row'><div class='col-sm-4 hidden-xs'>跳至 <input type='number' id='paginationNum' class='input-sm form-control inline v-middle text-center' style='width: 50px' ng-model='currentPage' ng-pattern='/^[0-9]+$/' ng-change='selectPage(currentPage=checkPage(1,totalPages,currentPage))' requied> 页,每页显示<select class='form-control input-sm' style='width: 100px;display: inline-block' ng-model='itemsPerPage' ng-options='count as count for count in pageSizes'></select>条</div><div class='col-sm-4 text-center'><small class='text-muted inline m-t-sm m-b-sm' ng-show='editPage'>总共{{totalItems}}条记录</small><small class='text-muted inline m-t-sm m-b-sm' ng-show='editPage'>/共{{totalPages}}页</small></div><div class='col-sm-4 text-right text-center-xs'><ul class='pagination m-t-none m-b-none'><li ng-if='boundaryLinks' ng-class='{disabled: noPrevious()}'><a href ng-click='selectPage(1)'><i class='fa fa-chevron-left'></i>{{getText('first')}}</a></li><li ng-if='directionLinks' ng-class='{disabled: noPrevious()}'><a href ng-click='selectPage(page - 1)'>{{getText('previous')}}</a></li><li ng-if='page.number==1||page.number==totalPages||(page.number-currentPage)*(page.number-currentPage)<=16' ng-repeat='page in pages track by $index' ng-class='{active: page.active}'><a href ng-if='page.number==1||page.number==totalPages||(page.number-currentPage)*(page.number-currentPage)<16' ng-click='selectPage(page.number)'>{{page.text}}</a><span ng-if='page.number!=1&&page.number!=totalPages&&(page.number-currentPage)*(page.number-currentPage)==16'>....</span></li><li ng-if='directionLinks' ng-class='{disabled: noNext()}'><a href ng-click='selectPage(page + 1)'>{{getText('next')}}</a></li><li ng-if='boundaryLinks' ng-class='{disabled: noNext()}'><a href ng-click='selectPage(totalPages)'><i class='fa fa-chevron-right'></i>{{getText('last')}}</a></li></ul></div></div>");
}]);

热心网友 时间:2022-05-16 01:35

1、插件源码主要基于angular directive来实现。 2、调用时关键地方是后台请求处理函数,也就是从后台取数据。 3、插件有两个关键参数currentPage、itemsPerPage,当前页码和每页的记录数。 4、实现方法调用后需要根据每次点击分页插件页码时重新...

热心网友 时间:2022-05-16 02:53

vuejs 不服
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
苹果电脑电池充不进电苹果电脑充不进去电是怎么回事 苹果电脑不充电没反应苹果电脑充电指示灯不亮充不了电怎么办 狗狗更加忠诚护家、善解人意,养一只宠物陪伴自己,泰迪能长多大... 描写泰迪狗的外形和特点的句子 国外留学有用吗 花钱出国留学有用吗 !这叫什么号 百万医疗赔付后是否可以续保 前一年理赔过医疗险还能续保吗? 医疗住院险理赔后还能购买吗? easyui的编辑表格和vue渲染数据有冲突吗? easyui和vue一起用为什么在分页上添加功能按钮会失效 vue中使用Swiper插件怎么修改他的分页器样式 vue2.0有好的分页插件吗 vue打印功能强制分页的同时,怎么给页脚加上页码? vuejs 上一页输入的数据会传到下一页,请问是怎么回事,求教如何修改! 使用vue-infinite-loading怎么分页加载 vue+element-ui分页功能 如何自动切换vue中的element中的分页 这Vue代码中分页和搜索框功能分别是怎么实现的。求解 vue element 分页,后台每次反给我10条数据,但是点击页码是空的,数据都是在第一页显示? Vue的H5页面唤起支付宝支付功能 vue组件滑到页脚进入下一页,然后再返回为什么会出现屏幕空白的情况 用vue怎么做有内容的分页,不用el-pagination组件 vue.js中怎么实现分页显示 了解乐视盒子怎么用? 乐视手机进入recovery模式然后怎么办? 乐视手机2连接电脑,怎么设置默认为媒体设备(MTP) 手机与电脑连接,但不能上传怎么办? 银行卡开通了短信功能,怎么通过短信查询银行卡余额 iphone 11亮度怎么调 苹果11自动调节亮度在哪 苹果11pro max亮度自动调节怎么关闭 iphone 11打开原彩没区别 苹果11有原彩但是显示屏幕不是原装的 为什么关了自动调节亮度还是会暗 有几题小学语文题 己所不欲勿施于人什么意思啊? 蜂还有什么同音字 同音字 顺口溜,比如峰、蜂、锋、风 请问斑纹锋,赤条蜂,黄蜂有什么共同点和不同点? 意蜂好还是黑锋好 蜂的甲骨文金文秦文隶文怎么写 这是什么蜂? 蜂还能加上什么偏旁组成新字。 收集关于蜜锋的信息 眉锋的锋是山峰的峰还是锋利的锋还是蜜蜂的蜂? 手机看小视频后很卡怎么办 考了税务师证没经验可以做什么工作 有了税务师证书能做什么??