我今天在看流星分页。
我对这次回购感兴趣:
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从简单的todo中对上面的代码进行分页?
我使用流星页面已经有一段时间了,但您应该能够用this.Tasks = new Meteor.Pagination("tasks");
替换Tasks = new Mongo.Collection("tasks");
——客户端和服务器之间的通用代码。
基本上,流星页面只是在mongo集合周围创建一个包装器,并应用搜索和过滤标准。
如果您熟悉coffeescript,请确保在repo中查看他们的/examples
目录。
此外,设置https://github.com/alethes/meteor-pages#settings将有助于解释一些默认值,如每页项目数等。