我已遵循各方示例中的目录格式。我对该项目进行的唯一修改就是运行:
mrt remove autopublish.
/model.coffee
Goals = new Meteor.Collection("goals")
Goals.allow
insert: (userId, goal) -> true
update: (userId, goal, fields, modifier) -> true
remove: (userId, goal) -> true
/server/server.coffee
Meteor.publish "goals", ->
return Goals.find({})
/client/main.coffee
Meteor.subscribe "goals"
Template.main.goals = ->
Goals.find({}, {sort: {name: 1}})
但是我收到以下错误:
Uncaught ReferenceError: Goals is not defined
奇怪的是,如果我将“Goals = new Meteor.Collection(”goals“)”添加到客户端脚本的顶部,我会收到此错误:
There is already a collection named 'goals'
答案 0 :(得分:3)
在model.coffee
文件中,在Goal
变量前加上@
符号前缀:
@Goals = new Meteor.Collection("goals")
这是在coffeescript中定义全局变量的方法。实际上@
编译为this.
,顶部范围this
是窗口对象,对于所有客户端文件都是相同的。