简体   繁体   English

用于分页的AngularJS自定义过滤器

[英]AngularJS custom filter for Pagination

I have implemented the following filter( startFrom ) in my app.js file: 我已经在我的app.js文件中实现了以下过滤器( startFrom ):

app.filter('startFrom', function () {
        return function (input, start) {
            start = +start;
            return input.slice(start);
        }
    });

I revice the data in an asychroneous way and the filter is applied at page load. 我以异步方式向数据发送消息,并且在页面加载时应用了过滤器。 The problem is that the data is not available when the filter is used. 问题是使用过滤器时数据不可用。

<div class="panel panel-default" ng-repeat="hotel in hotels | filter:search | startFrom:currentPage*itemsPerPage | orderBy:sortBy.Name :order.reverse | limitTo:itemsPerPage">

How can I have filter applied after the data is available? 数据可用后如何应用过滤器?

"A filter should always check the validity of its input. The input might be the result of an async operation, so the filter can't be sure the input is always what it's expecting for when it is being evaluated." “过滤器应始终检查其输入的有效性。输入可能是异步操作的结果,因此过滤器无法确保输入始终是评估时所期望的。”

Accordingly to words try this 据言尝试

 app.filter('startFrom', function () {
    return function (input, start) {
        if (!angular.isArray(input)) {
            return [];
        }
        start = +start;
        return input.slice(start);
    }
});

You haven't written but try to use only search and pagination filter, sometimes others filters can be the issue, so then you are sure that the problem is in your pagination filter. 您尚未编写但尝试仅使用搜索和分页过滤器,有时可能会出现其他过滤器,因此可以确定问题出在您的分页过滤器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM