AngularJS 前端分页

前端分页是什么?不知道

1、head 部分
<head>
    <link rel="stylesheet" href="/css/bootstrap.css">
    <script src="/js/angular/angular.js"></script>
    <script src="/js/angular-bootstrap/ui-bootstrap-tpls.js"></script>
  <script>
    angular.module('ui.bootstrap.demo', ['ui.bootstrap']).controller('PaginationDemoCtrl', function ($scope) {
      $scope.maxSize = 5;  // max-size 可以直接点击跳转的页数

      $scope.totalItems = 43;  //total-items 总条数
      $scope.pageSize = 6;  //items-per-page 每页显示条数
      $scope.currentPage = 1; //ng-model 当前页数
      $scope.numPages = Math.ceil($scope.totalItems/$scope.pageSize)  //num-pages 总页数 Math.ceil()向上取整

      $scope.allitem = []; //每页所有数据

      $scope.data = [];
      for(let i = 0; i < $scope.totalItems; i++) {
        let item = new Object();
        item.a = i;
        item.b = i;
        item.c = i;
        item.d = i;
        $scope.data.push(item);
      }

      getPageData();
      $scope.pageChanged = function() {
//        $log.log('Page changed to: ' + $scope.currentPage);
        getPageData();
      };

      function getPageData() {
        $scope.allitem = [];
        let index = $scope.pageSize * ($scope.currentPage -1);
        $scope.allitem.push($scope.data.slice(index, index + $scope.pageSize));
      }

    });

  </script>

  </head>

2、body 部分
<body>
 <div ng-controller="PaginationDemoCtrl">
   <div class="" style="height: 300px">
     <table class="table table-hover " style="text-align: center">
       <thead class="bg-primary">
         <tr style="text-align: center">
           <th style="text-align: center" i18nId="field">字段</th>
           <th style="text-align: center" i18nId="field">字段</th>
           <th style="text-align: center" i18nId="field">字段</th>
           <th style="text-align: center" i18nId="field">字段</th>
         </tr>
       </thead>
       <tbody>
         <tr ng-repeat="item in allitem[0]">
           <td ng-bind="item.a"></td>
           <td ng-bind="item.b"></td>
           <td ng-bind="item.c"></td>
           <td ng-bind="item.d"></td>
         </tr>
       </tbody>
     </table>
   </div>
   <ul uib-pagination total-items="totalItems" num-pages="numPages"
       items-per-page = "pageSize"
       ng-model="currentPage"
       ng-change = "pageChanged()"
       force-ellipses = "true"
       rotate = "true"
       max-size="maxSize"
       first-text="第一页" previous-text="上一页" next-text="下一页" last-text="最后页" boundary-links="true" boundary-link-numbers="true"></ul uib-pagination>
 </div>



 </body>

3、运行效果

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值