流星分页

时间:2016-08-25 23:35:51

标签: meteor pagination

我正在努力为我的论坛添加分页。你能救我吗?基本上,我期待在我的论坛页面上,只看到10个帖子。但它正在归还所有这些。 “加载更多”按钮也没有任何作用(看起来像)。

我正在使用此套餐:Paginated Subscription

以下是我正在使用的代码:

    if (Meteor.isClient) {

Deps.autorun(function() {
var handle = Meteor.subscribeWithPagination('posts',10);

});

Template.postsList.helpers({
    'posts': function(){
        return Posts.find({});
    }
});

Template.postsList.events({
    'click .btn': function(){
        handle.loadNextPage();
    }
})

}

if (Meteor.isServer) {
Meteor.startup(function () {
Meteor.publish("posts", function(limit){
return Posts.find({}, {limit: limit});
});

});

}

4 个答案:

答案 0 :(得分:0)

除非您将一些反应参数传递给var handle = Meteor.subscribeWithPagination('posts',10);,否则我不认为Deps需要位于handle区块中。

在Github上查看此Issue

答案 1 :(得分:0)

你可以使用Kurounin基于订阅的分页。它适用于我。在大气中,还有另一个反应分页你可以在Kurounin存储库中检查它

答案 2 :(得分:0)

我已经回答了这种问题。请参阅可以帮助您的确切代码。

Meteor Pagination Issue

答案 3 :(得分:0)

在您的出版物中,您必须使用排序(如文档所述)

  

//在此处使用sort是继续使用Oplog Observe的必要条件   驱动!

     

// https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver

Meteor.publish("posts", function(limit){
  return Posts.find({}, {
    limit: limit,
    sort: {
      createdAt: -1
    }
  });
});