2

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

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'
4

1 回答 1

3

在您的文件中,为您的变量添加model.coffee前缀:Goal@

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

这是在 coffeescript 中定义全局变量的方法。实际上@编译到this.并在顶部范围内this是窗口对象,所有客户端文件都相同。

于 2013-11-10T18:13:46.123 回答