This Meteor client side javascript needs to determine if the current user email has been verified.
Is there an easier way than to first check if the emails property is present and then check the first item in the array to see if it's property is set to true? Thanks
此Meteor客户端javascript需要确定当前用户电子邮件是否已经过验证。是否有一种比首先检查电子邮件属性是否存在更简单的方法,然后检查数组中的第一项以查看它的属性是否设置为true?谢谢
const val = Meteor.users.findOne({_id: userId}).emails[0].verified;
I know the code below can work in the html file but I need the value in the js file.
我知道下面的代码可以在html文件中工作,但我需要js文件中的值。
{{#unless currentUser.emails.[0].verified}}
1 个解决方案
#1
0
I've defined a global helper for this purpose:
我为此目的定义了一个全局帮助器:
// return true/false depending on whether the referenced user's email has been verified
Template.registerHelper('isVerified',function(){
return this.emails && this.emails[0].verified; // we're in a user context
else return Meteor.user().emails && Meteor.user().emails[0].verified; // look at the current user
});
Then from blaze:
然后从火焰:
{{#if isVerified}}...{{/if}}
Or from js:
或者来自js:
if ( UI._globalHelpers.isVerified() ) ...
#1
0
I've defined a global helper for this purpose:
我为此目的定义了一个全局帮助器:
// return true/false depending on whether the referenced user's email has been verified
Template.registerHelper('isVerified',function(){
return this.emails && this.emails[0].verified; // we're in a user context
else return Meteor.user().emails && Meteor.user().emails[0].verified; // look at the current user
});
Then from blaze:
然后从火焰:
{{#if isVerified}}...{{/if}}
Or from js:
或者来自js:
if ( UI._globalHelpers.isVerified() ) ...