过滤后更新AngularJS中的分页 [英] Update pagination in AngularJS after filtering

查看:29
本文介绍了过滤后更新AngularJS中的分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了分页.现在我希望在过滤结果后更新分页.

I already have the pagination implemented. Now I want the pagination to be updated after filtering my results.

形式:

<input type="text" data-ng-model="search.name" data-ng-change="filter()"/>

名单:

<li data-ng-repeat="data in filtered = (list | filter:search) | filter:search | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">{{data.name}}</li>

分页:

<pagination data-boundary-links="true" data-num-pages="noOfPages" data-current-page="currentPage" max-size="maxSize"></pagination>

控制器:

$scope.filter = function() {
    window.setTimeout(function() { //wait for 'filtered' to be changed
        $scope.noOfPages = Math.ceil($scope.filtered.length/$scope.entryLimit);
        $scope.setPage = function(pageNo) {
            $scope.currentPage = pageNo;
        };
    }, 10);
};

我的问题是,在单击页码或在输入字段中输入下一个字符后,分页才会更新.所以更新晚了一步.

My problem is, the pagination is just updated after clicking on a page number or after entering the next character into the input field. So it is update one step to late.

编辑:我将源代码添加到 jsFiddle:http://jsfiddle.net/eqCWL/2/

EDIT: I added the source to jsFiddle: http://jsfiddle.net/eqCWL/2/

推荐答案

使用 $timeout 而不是 window.setTimeOut.$timeout 被正确包装以在 Angular 中保持一致.

Use $timeout instead of window.setTimeOut. $timeout is wrapped properly to work consistently in Angular.

这篇关于过滤后更新AngularJS中的分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆