怎么办寻呼AngularJS? [英] How to do paging in AngularJS?
问题描述
我的内存约1000项的数据集,并在尝试创建一个寻呼机
此数据集,但我不确定如何做到这一点。
I have a dataset of about 1000 items in-memory and am attempting to create a pager for this dataset, but I'm unsure how to do this.
我使用的是自定义的过滤功能来过滤结果,而且工作得很好,但不知何故,我需要得到页数了。
I'm using a custom filter function to filter the results, and that works fine, but somehow I need to get the number of pages out.
任何线索?
推荐答案
查看的UI引导的分页指令。最后我用它,而不是什么张贴在这里,因为它有足够的功能,我目前的使用,有一个<一个href=\"https://github.com/angular-ui/bootstrap/blob/master/src/pagination/test/pagination.spec.js\">thorough测试规范陪它。
Angular UI Bootstrap - Pagination Directive
Check out UI Bootstrap's pagination directive. I ended up using it rather than what is posted here as it has enough features for my current use and has a thorough test spec to accompany it.
<!-- table here -->
<pagination
ng-model="currentPage"
total-items="todos.length"
max-size="maxSize"
boundary-links="true">
</pagination>
<!-- items/page select here if you like -->
控制器
todos.controller("TodoController", function($scope) {
$scope.filteredTodos = []
,$scope.currentPage = 1
,$scope.numPerPage = 10
,$scope.maxSize = 5;
$scope.makeTodos = function() {
$scope.todos = [];
for (i=1;i<=1000;i++) {
$scope.todos.push({ text:"todo "+i, done:false});
}
};
$scope.makeTodos();
$scope.$watch("currentPage + numPerPage", function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.filteredTodos = $scope.todos.slice(begin, end);
});
});
我已经做了工作plunker ,以供参考。
<!-- table here -->
<div data-pagination="" data-num-pages="numPages()"
data-current-page="currentPage" data-max-size="maxSize"
data-boundary-links="true"></div>
<!-- items/page select here if you like -->
控制器
todos.controller("TodoController", function($scope) {
$scope.filteredTodos = []
,$scope.currentPage = 1
,$scope.numPerPage = 10
,$scope.maxSize = 5;
$scope.makeTodos = function() {
$scope.todos = [];
for (i=1;i<=1000;i++) {
$scope.todos.push({ text:"todo "+i, done:false});
}
};
$scope.makeTodos();
$scope.numPages = function () {
return Math.ceil($scope.todos.length / $scope.numPerPage);
};
$scope.$watch("currentPage + numPerPage", function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage)
, end = begin + $scope.numPerPage;
$scope.filteredTodos = $scope.todos.slice(begin, end);
});
});
我已经做了工作plunker ,以供参考。
这篇关于怎么办寻呼AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!