Meteor:如何对简单的todos演示进行分页?

use*_*943 5 javascript pagination meteor

我今天看着Meteor的分页.

我对这个回购感兴趣:

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

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

this.Pages = new Meteor.Pagination("collection-name");
Run Code Online (Sandbox Code Playgroud)

和:

<body>
    {{> collection-name}}
</body>
<template name="collection-name">
    {{> pages}}
    {{> pagesNav}}  <!--Bottom navigation-->
</template>
Run Code Online (Sandbox Code Playgroud)

我想分页这个演示:

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");
  // ...
}
Run Code Online (Sandbox Code Playgroud)

和:

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

<template name="task">
  <li>
    {{text}}
  </li>
</template>
Run Code Online (Sandbox Code Playgroud)

也许今天我的大脑有点慢.我不清楚如何对上面的代码进行分页.

如何使用github.com/alethes/meteor-pages从simple-todos中分页上面的代码?

小智 0

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

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

如果您熟悉 CoffeeScript,请务必查看/examples存储库中的目录。

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