所以我试图从 Firestore 获取数据,当我控制台记录它时,我取回了我的集合内容,但是当我将代码移动到一个函数时,我无法将其返回。
此代码有效:
const db = firebase.firestore();
db.settings({ timestampsInSnapshots: true});
db.collection('story').get().then((snapshot) => {
snapshot.docs.forEach(doc => {console.log(doc.data())
;})
})
这不起作用。(它编译,但不返回任何东西):
...
getMyStory = () => {
const db = firebase.firestore();
db.settings({ timestampsInSnapshots: true});
db.collection('story').get().then((snapshot) => {
snapshot.docs.forEach(doc => {
let items = doc.data();
})
});
return this.items;
}
render () {
return (
<p>{this.getMyStory}</p>
);
}
我究竟做错了什么?