この流星サーバー・コードはパブリックメソッドでMeteor.userId()を使用しようとすると「のsendEmail」が、時々私はMeteor.userIdしか呼び出すことができ、エラーMeteor.userIdの正しい使用()
エラーを取得しますメソッド呼び出しで。使用this.userId
それは固定することができますどのように
lib = (function() {
return Object.freeze({
'sendEmail': function(msg){
let userId = Meteor.userId();
//do stuff for this user
},
'otherPublicMethod': function(){
//do other things then use sendEmail
lib.sendEmail(); // <---- Error Meteor.userId can only be invoked in method calls. Use this.userId
}
});
}());
// Now I call sendEmail from any where, or can I?
Meteor.methods({
'sendEmail': (msg) => {
lib.sendEmail(msg); // <---- NO error when this is called
},
});
? thx
'userId()'は 'Publications '内では使用できませんが、' Methods'内で使用することはできません。 –