我试图确定为什么我的全局变量在浏览器控制台中不可用。这是我的顶级流星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'});
});
}
我得到以下控制台输出(帖子为空):
是什么赋予了?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句