流星流用户

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.

  • 你可能想要`return Meteor.user()` (2认同)

Dan*_*scu 9

{{ currentUser }}是一个简单调用的模板助手Meteor.user().

在控制台中,您需要打电话Meteor.user().