【问题标题】:Angular Search with Pagination带分页的角度搜索
【发布时间】:2015-06-11 08:55:14
【问题描述】:

我正在尝试将搜索框与分页功能结合起来。

考虑以下图像列表的标记:

<div class="panel panel-info" ng-repeat="image in galleryCtrl.images |
startFrom: galleryCtrl.currentPage * galleryCtrl.resultsPerPageNum |
limitTo: galleryCtrl.resultsPerPageNum  | filter: search | orderBy: sort">

还有我的搜索框:

<div class="form-group" ng-hide="mySearch === 'false'">
    <label for="searchbox">Search: </label>
    <input type="text" id="searchbox" ng-model="search" 
    class="form-control" placeholder="What are we searching for?">
</div>

我的问题是,这样只会搜索当前页面中的图像。如果我搜索出现在第 2 页上的图像并且我在第 1 页上,则它不会作为结果出现。我怎样才能首先应用搜索过滤器而不是“分页”?

编辑 现在的问题是,在搜索框中输入超过 1 个字母后,没有搜索结果。 对于我的分页,我使用以下过滤器:

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

也许这就是问题所在?

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    您应该将filter: seach 移到过滤器列表的前面。这样数据首先被过滤,然后分页,然后排序。

    像这样:

    <div class="panel panel-info" ng-repeat="image in galleryCtrl.images | filter: search | startFrom: galleryCtrl.currentPage * galleryCtrl.resultsPerPageNum | limitTo: galleryCtrl.resultsPerPageNum | orderBy: sort">
    

    【讨论】:

    • 我相信排序也应该在分页之前。
    • 我也是,但这不是问题的一部分;)
    • 下一个问题将是“Angular sort filter is not working”:)
    • 感谢您的回答。我也移动了那种尤里嘿嘿。但奇怪的是,现在我根本看不到搜索结果,即使是来自同一页面的搜索结果
    • 如果你能创建一个小提琴来证明这个问题,那就太好了
    猜你喜欢
    • 1970-01-01
    • 2015-03-14
    • 2019-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多