[英]react-native-meteor Meteor.collection('xxx').findOne() return undefined, how to make a callback
當我嘗試獲取數據時,我不確定,但是在再次調用該方法后一秒鍾,我得到了想要的東西。 我的理解是,我只是等待響應,當我嘗試返回一個對象時,我什么也沒有,因為它在他的路上。 .findOne()沒有回調,在這種情況下我能做什么?
handleLogin = () => {
Meteor.loginWithPassword(this.state.loginField,this.state.passwordField,(error)=>{
if (!error) {
Meteor.subscribe('xxx')
let data = Meteor.collection('xxxy').findOne();
console.log(data);
}
}
}
您可能需要看一下本文檔的這一部分。 它說
當服務器將訂閱標記為就緒時,將不帶任何參數調用onReady回調。
基本上, Meteor.subscribe()
允許您包括在訂閱准備就緒時調用的回調。 它可能如下所示。
Meteor.subscribe('xxx', function () {
const data = Meteor.collection('xxxy').findOne()
console.log(data)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.