Disclaimer: I'm new to Meteor.
I'm working on some meteor client code that runs as a template helper and loads the username of a user with the provided id:
Template.message.helpers
editedBy: ->
return "" unless wasEdited(@)
if @edit.by
user = Meteor.users.findOne(@edit.by)
if user?
user.username
else
"?"
else
"?"
The issue with this code is that when it is invoked by the message template with the non-reactive render helper:
{{#each messagesHistory}}
{{#nrr nrrargs 'message' .}}{{/nrr}}
{{/each}}
and the message template is of the form:
<template name="message">
...
{{editedBy}}
...
</template>
The function returns ?
since the Meteor
lookup returns undefined. After debugging and adding some logging, I can verify that the @edit.by
id is the correct user id, and that calling Meteor.users.findOne(thatId)
loads the correct user (when I do it via the chrome javascript console).
What's going on here? I'm guessing it has something to do with when the data is available, but how do I fix it?
Thanks in advance!