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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:49:02  来源:igfitidea点击:

Meteor currentUser

javascriptmeteor

提问by Alexander Mills

Using the node.js framework Meteor -

使用 node.js 框架 Meteor -

how come the currentUservariable 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 currentUserfrom the console, it's undefined:

但是当我currentUser从控制台调用时,它是未定义的

enter image description here

在此处输入图片说明

however, Meteor.userIdis defined:

然而,Meteor.userId定义为:

enter image description here

在此处输入图片说明

why is this?

为什么是这样?

采纳答案by for_ever

{{ currentUser}}is a helper in the main_templatetemplate.

{{ 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.

这也可能有帮助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().