Meteor.publish回调未被调用

霍夫曼

我有一个非常简单的项目,只有一个Meteor.publish调用:

Boxes = new Meteor.Collection("boxes");

if (Meteor.isServer) {
  Meteor.startup(function () {
    Boxes.remove({}) //clearing the database
    Boxes.insert({ //adding one element to the database
      boxes: [1],
      currentId: 1
    });
  });
  console.log("publish1")
  Meteor.publish("boxes", function() {
    console.log("publish2") //this does not run! ever!
    return Boxes.find();
  });
}

由于某种原因,我的Meteor.subscribe似乎无法正常工作(集合总是返回空),因此我在代码中放置了两个console.log。由于某种原因,我的服务器代码显示“ publish1”,但不显示“ publish2”,而如果我在示例项目中尝试同样的操作,则它会同时显示两个。

注意:我删除了自动发布程序包。

Firdaus Ramlan

您需要在客户端上订阅它。这项工作对我来说:

Boxes = new Meteor.Collection("boxes");

if (Meteor.isServer) {
 Meteor.startup(function () {
  Boxes.remove({}) //clearing the database
  Boxes.insert({ //adding one element to the database
    boxes: [1],
    currentId: 1
  });
});
console.log("publish1")
Meteor.publish("boxes", function() {
    console.log("publish2") //this does not run! ever!
    return Boxes.find();
  });
}

if(Meteor.isClient){

  Meteor.subscribe('boxes');

}

publish2在浏览器中打开应用程序时唯一会打印的内容。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章