【发布时间】:2015-09-17 15:12:56
【问题描述】:
我正在关注 Discover Meteor.js 书并创建链接共享应用程序,但我希望基于周而不是按新近度进行分页。
目前代码的结构是根据 URL 显示一定数量的帖子:http://localhost:3000/
但我想显示最近一周提交的每个帖子,然后是前一周,等等。
这里是发布的帖子 mongo 集合:
Meteor.publish('posts', function(options){
check(options, {
sort: Object,
limit: Number,
});
return Posts.find({}, options);
});
这是路由器将数据传递给客户端的方式
PostsListController = RouteController.extend({
template: 'postsList',
increment: 5,
postsLimit: function() {
return parseInt(this.params.postsLimit) || this.increment;
},
findOptions: function() {
return {sort: {submitted: -1}, limit: this.postsLimit()};
},
subscriptions: function() {
this.postsSub = Meteor.subscribe('posts', this.findOptions());
},
posts: function() {
return Posts.find({}, this.findOptions());
},
data: function() {
var hasMore = this.posts().count() === this.postsLimit();
var nextPath = this.route.path({postsLimit: this.postsLimit() + this.increment});
return {
posts: this.posts(),
ready: this.postsSub.ready,
nextPath: hasMore ? nextPath : null
};
}
});
与 Product Hunt 类似,我如何按周对帖子进行分组、将该信息编码到 URL 并在页面底部创建一个链接以查看前一周的帖子?
谢谢!
【问题讨论】:
标签: meteor pagination