【发布时间】:2015-02-15 00:42:25
【问题描述】:
我有
var Schemas = {};
Meteor.isClient && Template.registerHelper("Schemas", Schemas);
Schemas.Person = new SimpleSchema({
fullName: {
type: String,
index: 1,
optional: true,
},
email: {
type: String,
optional: true
},
address: {
type: String,
optional: true
},
isActive: {
type: Boolean,
},
age: {
type: Number,
optional: true
}
});
在一个文件中
var Collections = {};
Meteor.isClient && Template.registerHelper("Collections", Collections);
Persons = Collections.Persons = new Mongo.Collection("Persons");
Persons.attachSchema(Schemas.Person);
在另一个文件中。
我收到错误 ReferenceError: Schemas is not defined。很明显,我必须在我的 collections.js 文件中定义 Schemas 而不是将它们分开。但是 Meteor 如何处理单独文件中的代码?我可以访问一些对象和变量,而另一些则无法访问。
【问题讨论】:
-
Schemas是全局变量吗?您是否使用require加载它?也许您需要向我们展示更多代码,因为编写代码时应该没有问题
标签: javascript node.js meteor scope