【发布时间】:2016-01-29 04:24:56
【问题描述】:
我正在做一个小应用程序,我在其中显示朋友请求和每个请求旁边的“接受/拒绝”按钮。
这是我的Template.notifications.helpers:
listRequests: function(){
return Notifications.find({toUser: Meteor.userId()});
}
这是我的通知(我在此显示好友请求的通知)模板:
<template name="notifications">
{{#each listRequests}}
<p>{{displayUserName}}
<span id="fromUserId"><strong>{{fromUser}}</strong></span> sent you a friend request.
<button class="btn btn-primary" id="btnAcceptRequest">Accept</button>
<button class="btn btn-danger" id="btnRejectRequest">Reject</button>
</p>
<p>{{createdAt}}</p>
{{/each}}
</template>
这是我的user 收藏:
{
"_id": "zaSuTBgRh3oQcPSkh",
"emails": [
{
"address": "johnsmith@yahoo.com",
"verified": false
}
],
"profile": {
"firstname": "John",
"lastname": "Smith"
}
}
目前,此代码有效。问题是它只显示发送请求的用户的_id,即fromUser。我想做的是显示请求用户的名字和姓氏,但我不知道从哪里开始。
当然,我尝试在Template helpers 上用{{profile.firstname profile.lastname}} 和return Meteor.users.find({}); 替换{{fromUser}},但它不起作用。谁能帮我这个?任何帮助将不胜感激。
【问题讨论】:
-
您能发布一下您的通知集合的样子吗?只是
toUser和fromUser吗? -
是的,它只包含
toUser、fromUser和createdAt
标签: javascript html mongodb meteor