我已经看到加载顺序上的一些事情,但事情似乎已经改变,因为1.0出来。让我说明我所看到的,也许有人可以告诉我我做错了什么:加载顺序:Meteor.js和Coffeescript
+ root-dir
|
+ - other stuff
|
+ main.coffee <- global declarations
|
+ lib
|
+ - charger_collection.coffee
|
+- charger_schema.coffee
这应该几乎覆盖它。现在,我意识到这不是目前的最佳做法,我不反对改变,但我需要了解为什么会发生以下问题。 main.coffee
包含此:
# Share globably accessible stuff like collections by
# attaching to 'this'
@Chargers = new Mongo.Collection("chargers")
和引用@Chargers其他文件可以作为你所期望的。例如: -
# client/chargers.coffee
Template.chargers.helpers
list: ->
return Chargers.find({}, {limit:50})
然而,问题就来了下面的使用行为,Collection2(节选)的优势:如果我使用@Chargers
或Chargers
发生
# lib/charger_schema.coffee
@Schemas = {}
@Schemas.Charger = new SimpleSchema
id:
type: Number
optional: false
name:
type: String
label: "Name"
max: 200
site_id:
type: Number
label: "Site ID"
"address.street":
type: String
label: "Street"
"address.city":
type: String
label: "City"
optional: true
@Chargers.attachSchema Schemas.Charger # <= TypeError: Cannot call method 'attachSchema' of undefined
此相同的错误。
两个问题:
为什么可视性问题?
如何解决问题?
谢谢!