Javascript 客户端代码未接收已发布的模型

Javascript 客户端代码未接收已发布的模型,javascript,meteor,Javascript,Meteor,我遵循了示例中的目录格式。我对项目所做的唯一修改是运行: 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 Met

我遵循了示例中的目录格式。我对项目所做的唯一修改是运行:

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
Meteor.publish "goals", ->
  return Goals.find({})
Meteor.subscribe "goals"

Template.main.goals = ->
  Goals.find({}, {sort: {name: 1}})
/server/server.coffee

Goals = new Meteor.Collection("goals")

Goals.allow
  insert: (userId, goal) -> true
  update: (userId, goal, fields, modifier) -> true
  remove: (userId, goal) -> true
Meteor.publish "goals", ->
  return Goals.find({})
Meteor.subscribe "goals"

Template.main.goals = ->
  Goals.find({}, {sort: {name: 1}})
/client/main.coffee

Goals = new Meteor.Collection("goals")

Goals.allow
  insert: (userId, goal) -> true
  update: (userId, goal, fields, modifier) -> true
  remove: (userId, goal) -> true
Meteor.publish "goals", ->
  return Goals.find({})
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'

model.coffee
文件中,在
Goal
变量前面加上
@
符号:

@Goals = new Meteor.Collection("goals")

这是在coffeescript中定义全局变量的方法。实际上,
@
编译成
这个。
在顶部范围中,
这个
是窗口对象,所有客户端文件都是如此。

我还发现我必须将models.coffee文件放在lib目录中,以便在服务器和客户端文件夹之前加载它。