我是Meteor的新手,我试图使用我的帖子类别
并使用paginated-subscription包我可以一次加载10个帖子并使用底部的加载更多按钮来获取下一个10个帖子,
但是当我显示不同类别的帖子时,我不能在每个类别中显示10个帖子,因为服务器一次只发布10个帖子,
我无法弄清楚如何在每个类别中发布10个帖子。我如何以这样的方式发布帖子,以便在每个类别中获得10个帖子?
答案 0 :(得分:0)
I checked out the paginated-subscription
s' source code. And found out that you can pass arguments to the publication. So you can do something like this for you publication:
Meteor.publish('posts', function(category, limit) {
var query = {}
if(category) query.category = category
return Posts.find(query, {limit: limit})
});
The last argument to the publication has to be the limit ("which expects as a final argument the current number of documents to display"). In your call to Meteor.subscribeWithPagination
you can now do this:
Meteor.subscribeWithPagination('posts', 'someCategory', 10)