【发布时间】: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