1
我想在服務器上使用觀察我的一個集合,但我需要獲取userId, 我試圖使用this.userId
和Meteor.userId()
,但不工作!請參閱下面的代碼以獲取更多詳細信息和錯誤消息 如何解決它?如何在觀察回調中獲取userId
Messages.find({state:"outbox"}).observe({
added: (doc) => {
console.log(" observe ");
console.log("userId : " + this.userId); // undefined
console.log("Meteor.userId(): " + Meteor.userId()); // "Exception in queued task: Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions."
//.......
}
});
感謝您的關注。
這是從發佈函數中調用,還是僅在服務器啓動時全局調用? –