I couldnt figure out why my Meteor template helper wasnt working on my Ubuntu server, so I just hacked together a couple variations and this one ended up working...locally I use if(user[0].trusted == true)
but for some reason that conditional wasnt getting triggered on the server.
Handlebars.registerHelper('isTrusted', function(user_id){
var user = Meteor.users.find({_id: user_id}).fetch();
console.log(user, 'user');
console.log(user[0].trusted);
if(user[0].trusted = true){
console.log(user[0].trusted, 'user trusted field');
return true;
} else {
false;
}
});
Why?
Your hack is wrong. It will always enter in the if branch, mostly because you are not comparing but assigning:
if(user[0].trusted = true)
Here you are assigning to user[0].trusted the true value. Because it's inside an if, javascript is checking if the assignment is correct. Because it assigned correctly, then it enters in the branch ( always ).
Send to console the value of user[0].trusted. Maybe it's a number, or has another value. Anyway, your code has a bug, it's not a thing with the server.
This may be a nice way to do it too:
Handlebars.registerHelper('isTrusted', function(user_id){
return !!Meteor.users.findOne({_id: user_id, trusted: true});
});
Or if you cast it to a string you can use 'true'
instead of true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.