Javascript 结合流星收集

Javascript 结合流星收集,javascript,meteor,infinite-scroll,Javascript,Meteor,Infinite Scroll,这个问题与此有关 简言之,我正在尝试构建一个新闻提要,很像Facebook的无限滚动功能。在这个新闻提要中,我想根据发布的日期显示来自不同集合的帖子。我有一个部分正常工作的代码(见下文),但问题是,因为我已将限制设置为3,刷新后,网站将为每个收藏提供3篇文章,而不是任何收藏的3篇最新文章 我想这是因为我出版这些收藏的方式,或者是我订阅它们的方式。代码如下: publish.js Meteor.publish('newsfeed', function(limit){ data = [

这个问题与此有关

简言之,我正在尝试构建一个新闻提要,很像Facebook的无限滚动功能。在这个新闻提要中,我想根据发布的日期显示来自不同集合的帖子。我有一个部分正常工作的代码(见下文),但问题是,因为我已将
限制设置为3,刷新后,网站将为每个收藏提供3篇文章,而不是任何收藏的3篇最新文章

我想这是因为我出版这些收藏的方式,或者是我订阅它们的方式。代码如下:

publish.js

Meteor.publish('newsfeed', function(limit){
  data = [
    Status.find({}, {limit:limit, sort: {createdAt:-1}}),
    Story.find({}, {limit:limit, sort: {createdAt:-1}}),
    Lesson.find({}, {limit:limit, sort: {createdAt:-1}}),
    Images.find(),
    Documents.find()
  ];
  return data;
});
newsfeed_increment = 3;
Session.setDefault('newsfeedLimit', newsfeed_increment);
Deps.autorun(function(){
  Meteor.subscribe('newsfeed', Session.get('newsfeedLimit'));
});

Template.statusBox.helpers({
  //Merging few collections into one template helper: https://stackoverflow.com/questions/21296712/merging-collections-in-meteor
  newsfeedList: function(){
    var hza = Status.find().fetch()
      .concat(Story.find().fetch())
      .concat(Lesson.find().fetch());
      var sortie = _.sortBy(hza, function(doc) { return doc.createdAt; });
      var ietros = sortie.reverse();
      return ietros;
...
});
Template.statusBox.helpers({
  newsfeedList: function(){
    var limit = Session.get('newsfeedLimit');
    var hza = Status.find({limit:limit, sort: {createdAt:-1}).fetch()
      .concat(Story.find({limit:limit, sort: {createdAt:-1}).fetch())
      .concat(Lesson.find({limit:limit, sort: {createdAt:-1}).fetch());
    var sortie = _.sortBy(hza, function(doc) { return doc.createdAt; });
    var ietros = sortie.reverse();
   return ietros;
   ...
});
statusBox.js

Meteor.publish('newsfeed', function(limit){
  data = [
    Status.find({}, {limit:limit, sort: {createdAt:-1}}),
    Story.find({}, {limit:limit, sort: {createdAt:-1}}),
    Lesson.find({}, {limit:limit, sort: {createdAt:-1}}),
    Images.find(),
    Documents.find()
  ];
  return data;
});
newsfeed_increment = 3;
Session.setDefault('newsfeedLimit', newsfeed_increment);
Deps.autorun(function(){
  Meteor.subscribe('newsfeed', Session.get('newsfeedLimit'));
});

Template.statusBox.helpers({
  //Merging few collections into one template helper: https://stackoverflow.com/questions/21296712/merging-collections-in-meteor
  newsfeedList: function(){
    var hza = Status.find().fetch()
      .concat(Story.find().fetch())
      .concat(Lesson.find().fetch());
      var sortie = _.sortBy(hza, function(doc) { return doc.createdAt; });
      var ietros = sortie.reverse();
      return ietros;
...
});
Template.statusBox.helpers({
  newsfeedList: function(){
    var limit = Session.get('newsfeedLimit');
    var hza = Status.find({limit:limit, sort: {createdAt:-1}).fetch()
      .concat(Story.find({limit:limit, sort: {createdAt:-1}).fetch())
      .concat(Lesson.find({limit:limit, sort: {createdAt:-1}).fetch());
    var sortie = _.sortBy(hza, function(doc) { return doc.createdAt; });
    var ietros = sortie.reverse();
   return ietros;
   ...
});

有什么想法吗?

您也应该在客户端(即,在

statusBox.js

Meteor.publish('newsfeed', function(limit){
  data = [
    Status.find({}, {limit:limit, sort: {createdAt:-1}}),
    Story.find({}, {limit:limit, sort: {createdAt:-1}}),
    Lesson.find({}, {limit:limit, sort: {createdAt:-1}}),
    Images.find(),
    Documents.find()
  ];
  return data;
});
newsfeed_increment = 3;
Session.setDefault('newsfeedLimit', newsfeed_increment);
Deps.autorun(function(){
  Meteor.subscribe('newsfeed', Session.get('newsfeedLimit'));
});

Template.statusBox.helpers({
  //Merging few collections into one template helper: https://stackoverflow.com/questions/21296712/merging-collections-in-meteor
  newsfeedList: function(){
    var hza = Status.find().fetch()
      .concat(Story.find().fetch())
      .concat(Lesson.find().fetch());
      var sortie = _.sortBy(hza, function(doc) { return doc.createdAt; });
      var ietros = sortie.reverse();
      return ietros;
...
});
Template.statusBox.helpers({
  newsfeedList: function(){
    var limit = Session.get('newsfeedLimit');
    var hza = Status.find({limit:limit, sort: {createdAt:-1}).fetch()
      .concat(Story.find({limit:limit, sort: {createdAt:-1}).fetch())
      .concat(Lesson.find({limit:limit, sort: {createdAt:-1}).fetch());
    var sortie = _.sortBy(hza, function(doc) { return doc.createdAt; });
    var ietros = sortie.reverse();
   return ietros;
   ...
});