【发布时间】:2014-01-09 17:56:27
【问题描述】:
我的 Meteor 项目的 server/server 目录中有一个名为 authServices.coffee 的文件。它具有以下函数定义,后跟Meteor.methods 调用:
isAuthorized = () ->
# note that at this point there is ever to be but one authorized user
authorized = Assets.getText('authorizedUsers').trim()
this.userId.trim() is authorized
这不起作用——也就是说,调用Meteor.call 'getKey'会返回undefined
Meteor.methods(
isAuthorized : isAuthorized
getKey : () ->
if isAuthorized()
Assets.getText('Key')
)
但如果我在上述getKey 中内联isAuthorized,它会返回true(给定正确的输入)
我猜这是this 对这些对象的行为方式的函数,但无法完全掌握它。
【问题讨论】:
-
除了发布函数和方法之外,您不必在任何地方使用 Meteor.userId 代替 this.userId 吗?
-
将
this中的Meteor.userId更改为authorizedUsers我得到throw new Error("Meteor.userId can only be invoked in method calls. Use this.userId in publish functions."); // 17
标签: javascript coffeescript meteor