【问题标题】:Meteor: how to paginate simple-todos demo?Meteor:如何对 simple-todos 演示进行分页?
【发布时间】:2016-03-20 14:11:00
【问题描述】:

我今天在看 Meteor 分页。

我对此回购感兴趣:

https://github.com/alethes/meteor-pages

显示的初始代码看起来很简单:

this.Pages = new Meteor.Pagination("collection-name");

和:

<body>
    {{> collection-name}}
</body>
<template name="collection-name">
    {{> pages}}
    {{> pagesNav}}  <!--Bottom navigation-->
</template>

我想给这个演示分页:

https://github.com/meteor/simple-todos

我在那里看到的代码简化为:

Tasks = new Mongo.Collection("tasks");

if (Meteor.isServer) {
  // This code only runs on the server
  Meteor.publish("tasks", function () {
    return Tasks.find({})})}


if (Meteor.isClient) {
  // This code only runs on the client
  Meteor.subscribe("tasks");
  // ...
}

和:

<body>
    <ul>
      {{#each tasks}}
        {{> task}}
      {{/each}}
    </ul>
</body>

<template name="task">
  <li>
    {{text}}
  </li>
</template>

也许我今天的大脑有点慢。 如何对上面的代码进行分页对我来说并不明显。

如何使用 github.com/alethes/meteor-pages 从 simple-todos 中对上述代码进行分页?

【问题讨论】:

  • 在 minimongo 中获取任务后,应在获取适当的页面数据之前应用过滤条件、排序条件。如果记录数过多,则通过 minimongo 的默认流星机制表现不佳。 Mini-mongo 最适合小型收藏。对于大型集合,使用具有相同标准的服务器 Meteor 方法。

标签: javascript meteor pagination


【解决方案1】:

自从我使用流星页面已经有一段时间了,但是您应该可以将 Tasks = new Mongo.Collection("tasks"); 替换为 this.Tasks = new Meteor.Pagination("tasks"); - 客户端和服务器之间的通用代码。

基本上,流星页面只是围绕 mongo 集合创建一个包装器并应用搜索和过滤条件。

如果您熟悉 coffeescript,请务必查看他们在 repo 中的 /examples 目录。

此外,设置https://github.com/alethes/meteor-pages#settings 将有助于解释一些默认设置,例如每页项目等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    • 2011-12-01
    • 1970-01-01
    相关资源
    最近更新 更多