如何在AngularJS中进行寻呼?我有一个内存中大约有1000个项的数据集,并且试图为这个数据集创建一个寻呼机,但是我不确定如何做到这一点。我正在使用一个自定义的过滤器函数来过滤结果,这很好,但不知怎么的,我需要得到页数。有什么线索吗?
3 回答
慕仙森
TA贡献1827条经验 获得超7个赞
角UI引导-分页指令
检查UI引导氏分页指令..我最终使用了它,而不是这里发布的内容,因为它有足够的特性来满足我当前的使用,并且有一个彻底测试规范陪着它。
视点
<!-- 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); });});
遗留版本:
视点
<!-- 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); });});
- 3 回答
- 0 关注
- 508 浏览
添加回答
举报
0/150
提交
取消