【问题标题】:Meteor Easy Search Pagination IntegrationMeteor 轻松搜索分页集成
【发布时间】:2015-05-02 12:46:26
【问题描述】:

我正在使用 meteor-easy-search 包将搜索和分页集成到我的应用程序中: https://github.com/matteodem/meteor-easy-search

我有它的工作,有点。搜索就像一个魅力,但分页是相当错误的。我想每页显示 25 个结果。如果结果少于 25 个,显然所有这些结果都应显示在第一页上。如果有 70 个结果,则第一页应显示 25,第二页应显示 25,第三页应显示 20。

目前发生的情况是第 1 页可能是随机空白,第 2 页显示大约 8 条记录,第 3 页将显示其余记录。而且并不总是按这个顺序。第 1 页可能显示 15 条记录,第 2 页和第 3 页显示其余记录。另外,我正在尝试按日期对结果进行排序,最近的出现在最前面。这也无法正常工作。它似乎适用于结果的第一部分,但最后结果将有一个不合适的随机条目。

我感觉我的实现在某个地方出现了问题,导致了这些奇怪而随机的问题。有人可以看看,让我知道我做错了什么吗?

在客户端:

    Template.history.rendered = function () {

      var instance = EasySearch.getComponentInstance(
        { id : 'search', index : 'items' }
      );
      EasySearch.changeLimit('items', 25);
      EasySearch.pagination('items', EasySearch.PAGINATION_NEXT); // Go to the second step
    };

在客户端和服务器上:

    Items = new Mongo.Collection("items");

    EasySearch.createSearchIndex('items', {
      'collection': Items,
      'field': ["details","createdAt"],
      'limit': 10,
      'use' : 'mongo-db',
      'props': {
        'sortBy': 'asc'
      },
      'sort': function() {
        if (this.props.sortBy === 'asc') {
          return { 'createdAt': -1 };
        }
      },
      'query': function(searchString, opts) {
        var query = EasySearch.getSearcher(this.use).defaultQuery(this, searchString);
        return query;
      }
    });

在历史html模板中:

      {{> esInput allDocsOnEmpty=true index="items" id="search" placeholder="Search now..." }}
      {{> esPagination index="items" id="search" }}

      {{#esEach index="items" id="search"}}
        {{#if isOwner username }}
      <tr style="height: 150px;">
        <td>{{ username }}</td>
        <td>{{ formatTime createdAt }}</td>
        <td> {{ details }} </td>
      </tr>
        {{/if}}
      {{/esEach}}

【问题讨论】:

    标签: meteor


    【解决方案1】:

    我没有确切的解决方案,但我认为您已经定义了 2 个限制。一个在索引中,另一个在结果中,但我认为它们可能会发生冲突? 25和10?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      • 2018-08-17
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多