流星中的全局变量

亚历山大·米尔斯

我试图确定为什么我的全局变量在浏览器控制台中不可用。这是我的顶级流星javascript文件内容:

     if (Meteor.isServer) {
        Meteor.startup(function () {

         Posts = new Mongo.Collection("posts");
         Carbrands = new Meteor.Collection("carbrands");
         Comments = new Mongo.Collection("comments");

         Posts.insert({post1:'post'});
         Carbrands.insert({post1:'post'});
         Comments.insert({post1:'post'});
      });
     }

(我可以确认已定义“帖子”,“ Carbrands”,“评论”),但在浏览器中,我得到了此信息(“帖子”未定义):

在此处输入图片说明 但是,当我在顶部添加以下代码行时:

Posts = null;

     if (Meteor.isServer) {
         Meteor.startup(function () {

      Posts = new Mongo.Collection("posts");
      Carbrands = new Meteor.Collection("carbrands");
      Comments = new Mongo.Collection("comments");

      Posts.insert({post1:'post'});
      Carbrands.insert({post1:'post'});
      Comments.insert({post1:'post'});
      });
     }

我得到以下控制台输出(帖子为空):

在此处输入图片说明

是什么赋予了?

乙烷

尝试在/lib文件夹中声明Collections

因此它们将同时可用 client/server

Meteor一样,docs/lib文件夹是声明集合的好地方

lib /#通用代码,例如集合和实用程序

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章