如何在AngularJS中進行尋呼?我有一個內存中大約有1000個項的數據集,并且試圖為這個數據集創建一個尋呼機,但是我不確定如何做到這一點。我正在使用一個自定義的過濾器函數來過濾結果,這很好,但不知怎么的,我需要得到頁數。有什么線索嗎?
3 回答
慕仙森
TA貢獻1827條經驗 獲得超8個贊
角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 關注
- 543 瀏覽
添加回答
舉報
0/150
提交
取消
