Ale*_*lls 11 javascript meteor
使用node.js框架Meteor -
为什么currentUser变量是在模板中定义的,例如:
<template name="main_template">
<div class="container">
{{#if currentUser}}
{{> add_player_form_template}}
{{/if}}
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
但是当我currentUser从控制台调用时,它是未定义的:

但是,Meteor.userId定义如下:

为什么是这样?
小智 11
{{ currentUser}}是main_template模板中的帮助器.
在您的客户端Javascript中,您需要定义该帮助方法.就像是:
Template.main_template.helpers({
currentUser: function() {
return Meteor.userId();
}
})
Run Code Online (Sandbox Code Playgroud)
这也可能有助于http://docs.meteor.com/#/basic/templates.