javascript - Meteor return name from previous query -
i'm doing small app display friend requests , 'accept/reject' button beside each request.
here's template.notifications.helpers:
listrequests: function(){ return notifications.find({touser: meteor.userid()}); } and here's notifications (where display notifications friend requests) template:
<template name="notifications"> {{#each listrequests}} <p>{{displayusername}} <span id="fromuserid"><strong>{{fromuser}}</strong></span> sent 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> and here's user collection:
{ "_id": "zasutbgrh3oqcpskh", "emails": [ { "address": "johnsmith@yahoo.com", "verified": false } ], "profile": { "firstname": "john", "lastname": "smith" } } currently, code works. issue displays _id of user sent request, thus, fromuser. wanted display firstname , lastname of requesting user don't know go here.
of course, tried replacing {{fromuser}} {{profile.firstname profile.lastname}} , return meteor.users.find({}); on template helpers not work. can me this? appreciated.
you need helper lookup of other user document , returns appropriate values:
template.notifications.helpers({ fromusername: function(){ var fromuser = meteor.users.findone({ _id: this.fromuser }); if ( fromuser ){ return fromuser.profile.firstname + ' ' + fromuser.profile.lastname; } } }); note if have removed autopublish must publishing profile field (at least) user collection server , subscribing on client.
Comments
Post a Comment