【问题标题】:Why is my Meteor UserId not displaying with this code?为什么我的 Meteor UserId 没有与此代码一起显示?
【发布时间】:2015-09-10 16:43:47
【问题描述】:

我想(出于好奇)在试用 Meteor 应用程序时查看我的 userId。我正在尝试以这种方式显示它:

HTML:

<body>
. . .
<div class="container">
   {{> userIdTemplate}}
   {{> postTravelWizard}}
</div>

</body>

<template name="userIdTemplate">
  {{getUserId}}
</template>

Javascript:

Template.userIdTemplate.helpers({
     getUserId: function () {
       return Meteor.userId;
     }
   });

在 CDT 中单步浏览 .js,我看到 Meteor.userId 的值是“未定义”。我没有经过身份验证 - 只需运行仍然安装了不安全包的应用程序。这就是 userId 未定义的原因吗?

【问题讨论】:

    标签: html spacebars meteor-accounts meteor-helper isomorphic-javascript


    【解决方案1】:

    在您登录之前,Meteor.userId() 和 Meteor.user() 都将返回 null,根据 docs。此外,您的代码有一个错字Meteor.userId。应该是Meteor.userId()(注意函数调用)。

    【讨论】:

      猜你喜欢
      • 2021-01-03
      • 1970-01-01
      • 2023-03-31
      • 2019-12-20
      • 2016-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多