栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何对使用ng-repeat生成的表使用UI Bootstrap分页

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何对使用ng-repeat生成的表使用UI Bootstrap分页

您缺少的部分是必须具有从整个数组中获取当前页面数据的功能。我添加了一个函数

setPagingData()
来处理此问题。

您可以在分叉的拨蓬中看到这一点

var app = angular.module("plunker", ["ui.bootstrap"]);app.controller("MainCtrl", function($scope) {  var allCandidates =      ["name1", "name2", "name3", "name4", "name5",       "name6", "name7", "name8", "name9", "name10",       "name11", "name12", "name13", "name14", "name15",       "name16", "name17", "name18", "name19", "name20"      ];  $scope.totalItems = allCandidates.length;  $scope.currentPage = 1;  $scope.itemsPerPage = 5;  $scope.$watch("currentPage", function() {    setPagingData($scope.currentPage);  });  function setPagingData(page) {    var pagedData = allCandidates.slice(      (page - 1) * $scope.itemsPerPage,      page * $scope.itemsPerPage    );    $scope.aCandidates = pagedData;  }});<link data-require="bootstrap-css@*" data-semver="4.0.0-alpha.2" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" /><script>document.write('<base href="' + document.location + '" />');</script><script data-require="angular.js@1.4.x" src="https://pre.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script><script data-require="ui-bootstrap@*" data-semver="1.3.2" src="https://cdn.rawgit.com/angular-ui/bootstrap/gh-pages/ui-bootstrap-tpls-1.3.2.js"></script><div ng-app="plunker">  <div ng-controller="MainCtrl">    <table id="mytable" >      <thead>        <tr >          <th>Name</th>        </tr>      </thead>      <tbody>        <tr ng-repeat="person in aCandidates">          <th> <div>{{person}}</div>          </th>        </tr>      </tbody>    </table>    <uib-pagination total-items="totalItems" ng-model="currentPage" items-per-page="itemsPerPage"></uib-pagination>  </div></div>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/633498.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号