meteor - this.userId not displaying user -


i'm publishing users , second collection called joboffers. joboffers collection stores userids employer , candidate. candidate name display next joboffer, admin page, nothing seems work. of joboffers display not candidate name. in console object .

path: publish.js

// publish jobs admin view meteor.publish('alljobs', function () {   return joboffers.find({}); });  meteor.publish('alluserswithjobs', function () {   var offers = joboffers.find({}, {fields: {candidateuserid: 1}}).fetch();   var ids = _.pluck(offers, 'candidateuserid');    options = { fields: {username: 1, emails: 1, "profile.firstname": 1, "profile.familyname": 1 } };   return meteor.users.find({ _id: { $in: ids } }, options);      }); 

path: alljoboffers.js

template.alljoboffers.oncreated(function() {   meteor.subscribe("alljobs");   meteor.subscribe("alluserswithjobs");  });      template.alljoboffers.helpers({         alljoboffers: function() {              return joboffers.find({});         },         candidatename: function() {                  console.log(this);              var user = this.userid;             var candidate = (user && user.profile && user.profile.firstname);              return candidate;         },     }); 

path: alljoboffers.html

{{#each alljoboffers}}     {{positiontitle}}      {{#with candidatename}}         {{profile.firstname}}     {{/with}} {{/each}} 

you're mixing user id , user object. it's idea create global helper keep convention on how manage them. reduce confusion. example:

template.registerhelper('usernamebyid', function(userid) {   var user = meteor.users.findone({_id: userid});   return user && user.profile.firstname; }); 

then in template:

{{#each alljoboffers}}   {{positiontitle}}   {{usernamebyid candidateuserid}} {{/each}} 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -