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

Client code is not receiving a published model

本文关键字:模型 代码 客户端      更新时间:2023-09-26

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

mrt remove autopublish.

/模型咖啡

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 

奇怪的是,如果我在客户端脚本的顶部添加"目标=新的Meteor.Collection("目标")",我会收到此错误:

There is already a collection named 'goals'

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

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

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