什么是最简单的方式来创建分页? 我喜欢用ng-repeat来检查项目列表,每个项目都有id和name属性。下一个代码适用于例如15个项目和显示2个页面,但是我想显示第一个页面的前10个项目,另一个页面显示其他项目...等等,如果我有很多项目。如何使用ngrepeat和bootstrap ui使用angularjs创建分页?
我的代码我的尝试:
<table>
<thead><th>id</th><th>name</th></thead>
<tbody><tr ng-repeat="item in items">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
</tr></tbody>
</table>
<uib-pagination total-items="totalItems" ng-model="currentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" force-ellipses="true"></uib-pagination>
<script>
$scope.items = [] //here i have for example 15 items..it comes through rest
totalItems = $scope.items.length; //15
$scope.currentPage=1;//1. page
$scope.maxSize=4; //maximum 4 page show
</script>
可能有人帮助我吗?非常感谢!
你的问题不是很清楚。您是否试图在每页显示固定数量的项目?或者你是否动态地试图控制每页的项目数量? –
ui-bootstrap默认为每页10个,所以我只想在一页中显示前10项第二页最后5项....如果35个项目出现:第一页10秒10第三10和最后5. – kissmark
所以我想每页最多允许10个项目,当我有超过10个项目时做分页 – kissmark