Javascript Meteor JS:RegisterHelper显示相关的用户信息
我正在开发一个小型MeteorJS应用程序(供个人使用),这将是一个非常基本的CMS 我想在每个帖子(创建帖子的用户)旁边显示用户信息 这是我的把手(或空格键)模板:Javascript Meteor JS:RegisterHelper显示相关的用户信息,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,我正在开发一个小型MeteorJS应用程序(供个人使用),这将是一个非常基本的CMS 我想在每个帖子(创建帖子的用户)旁边显示用户信息 这是我的把手(或空格键)模板: <template name="post"> <div class="row"> <div class="col-md-7"> <h3>{{ title }} - <span class="time" title="{{createdAt}}">{
<template name="post">
<div class="row">
<div class="col-md-7">
<h3>{{ title }} - <span class="time" title="{{createdAt}}">{{createdAt}}</span></h3>
<p>Created By - {{ user_id }}</p>
{{{content}}}
</div>
<div class="col-md-5">
{{> editActions }}
</div>
</div>
</template>
<template name="editActions">
<ul class="nav nav-pills">
<li>
<a href="{{ pathFor 'postEdit' }}">
<i class="glyphicon glyphicon-edit"></i>
</a>
</li>
<li>
<a href="{{ pathFor 'postRemove' }}" data-id="{{ _id }}" class="remove-post">
<i class="glyphicon glyphicon-remove"></i>
</a>
</li>
</ul>
</template>
{{title}}-{{createdAt}
由-{{user_id}创建
{{{content}}}
{{>编辑操作}
-
-
我有{{user_id}}
显示,但我不确定如何显示实际的用户电子邮件(或任何其他用户信息)
user\u id
是我的Posts
集合中的一个字段。将{{user\u id}
替换为{authorEmail}
,然后添加如下模板帮助器:
Template.post.helpers({
authorEmail: function() {
return Meteor.users.findOne(this.user_id).emails[0].address;
}
});
如果希望直接访问模板中的作者,可以从助手返回用户文档:
Template.post.helpers({
author: function() {
return Meteor.users.findOne(this.user_id);
}
});
然后像这样使用它:
<div class="col-md-7">
<h3>{{ title }} - <span class="time" title="{{createdAt}}">{{createdAt}}</span></h3>
{{#with author}}
<p>Created By - {{profile.name}}</p>
{{/with}}
{{{content}}}
</div>
{{title}}-{{createdAt}
{{{与作者}
创建人-{profile.name}
{{/与}}
{{{content}}}