javascript 流星当前用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28334886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Meteor currentUser
提问by Alexander Mills
Using the node.js framework Meteor -
使用 node.js 框架 Meteor -
how come the currentUser
variable is definedin a template such as here:
为什么currentUser
变量是在模板中定义的,比如这里:
<template name="main_template">
<div class="container">
{{#if currentUser}}
{{> add_player_form_template}}
{{/if}}
</div>
</template>
but when I call currentUser
from the console, it's undefined:
但是当我currentUser
从控制台调用时,它是未定义的:
however, Meteor.userId
is defined:
然而,Meteor.userId
定义为:
why is this?
为什么是这样?
采纳答案by for_ever
{{ currentUser}}
is a helper in the main_template
template.
{{ currentUser}}
是main_template
模板中的帮手。
In your client Javascript you'll need to define that helper method. Something like:
在您的客户端 Javascript 中,您需要定义该辅助方法。就像是:
Template.main_template.helpers({
currentUser: function() {
return Meteor.userId();
}
})
This may help too http://docs.meteor.com/#/basic/templates.
回答by Dan Dascalescu
{{ currentUser }}
is a template helper that simply calls Meteor.user()
.
{{ currentUser }}
是一个模板助手,只需调用Meteor.user()
.
In the console, you need to call Meteor.user()
.
在控制台中,您需要调用Meteor.user()
.