【问题标题】:Meteor profile page check if current user is page ownerMeteor 个人资料页面检查当前用户是否是页面所有者
【发布时间】:2016-03-30 04:22:17
【问题描述】:

我已经为我的所有用户建立了一个 Meteor 项目,其中包含以下问题的答案的指导:SO Question

如果用户是个人资料页面的所有者,我想知道如何向用户显示编辑按钮。

例如,这是我的模板:

<template name="profile">
{{#if <!-- Insert condition here -->}}
  <!-- page owner content only -->
{{/if}}
<!-- Content for all to see -->
</template>

我需要在车把中放置什么条件才能仅显示页面所有者内容?是模板助手还是我可以自己设置条件?

只是对路由中的数据来自哪里以及可以在哪里使用等有点困惑。

【问题讨论】:

    标签: javascript meteor iron-router user-profile


    【解决方案1】:

    您可以创建一个帮助程序来分析用户登录它是否与您用于访问页面的路径相同。像这样的:

    Template.profile.helpers({
        'isMyProfile': function() {
            return Router.current().params.username == Meteor.user.username
        }
    });
    

    然后在模板上,你可以调用:

    {{#if isMyProfile}}
        <button>...</button>
    {{/if}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 2011-12-12
      • 2015-05-10
      相关资源
      最近更新 更多