[英]'==' works locally but '=' required for comparison on server
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. 我不知道为什么我的Meteor模板助手不能在我的Ubuntu服务器上工作,所以我只是一起破解了几个变体,而这个变体最终奏效了……我在本地使用if(user[0].trusted == true)
但是对于服务器没有触发条件性的某些原因。
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. 您的hack是错误的。 It will always enter in the if branch, mostly because you are not comparing but assigning: 它将始终输入if分支,主要是因为您不是在进行比较而是分配:
if(user[0].trusted = true)
Here you are assigning to user[0].trusted the true value. 在这里,您将分配给user [0] .trusted的真实值。 Because it's inside an if, javascript is checking if the assignment is correct. 由于它位于if中,因此javascript正在检查分配是否正确。 Because it assigned correctly, then it enters in the branch ( always ). 由于分配正确,因此它将进入分支( 始终 )。
Send to console the value of user[0].trusted. 将用户[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
或者,如果将其强制转换为字符串,则可以使用'true'
代替true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.