【发布时间】:2015-05-03 17:58:00
【问题描述】:
您好,我有一个简单的应用程序列表帖子,我正在努力使用 Iron Router 和 Meteor Pagination 添加一个简单的分页:https://github.com/egtann/meteor-pagination
我的 index.js 中有以下内容:
if (Meteor.isClient) {
Template.index.helpers({
posts: function () {
return Posts.find({}, {sort: {voteResult: -1}});
},
}
因此要在我的 index.html 中显示我使用 {{#each posts}} 的帖子,如下所示:
<template name="index">
<ul>
{{#each posts}}
<li>
{{text}}
</li>
{{/each}}
</ul>
<!-- pagination BOOTSTRAP CSS -->
<!-- <div class="text-center">
<ul class="pagination_bis">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<li class="active_bis"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</div> -->
</template>
这是我的 route.js:
Router.configure({
loadingTemplate: 'loading',
notFoundTemplate: 'notFound',
layoutTemplate: 'layout'
});
Router.route('/', function() {
this.render('index');
});
我的问题:
- 如何在 routes.js (Iron Router) 中定义我的路由以进行简单的分页?
- 如何使用我的 index.js 中的路由和使用 Meteor 分页(上面提供的链接)的助手,以便它仅基于每页返回有限数量的帖子?
- 如何将此逻辑连接到视图 (index.html)?
我尝试按照上面提供的链接示例进行操作,但我很困惑,他们使用的 Meteor 版本已被弃用。不用说,我是 Meteor 的新手,每一个输入都非常感谢。供您参考,应用程序事件工作正常,我设法保存和删除帖子,为测试分页创建了 30 多个帖子。谢谢。
【问题讨论】:
标签: meteor pagination iron-router