【问题标题】:Need Help in retrieving data value from firestore需要帮助从 Firestore 中检索数据值
【发布时间】:2019-03-13 16:47:34
【问题描述】:

我想从 Firestore 中检索数据,但我似乎无法检索它。

在我的 user.ts 提供程序中

getUserEventData() {
  var sDoc = this.afs.doc(`users/${this.afAuth.auth.currentUser.uid}`).collection('events').doc('volunteer');
  sDoc.snapshotChanges().forEach(element => {
    return element.payload.data;
  });
}

firestore 索引

I want to retrieve the name/value of "Bandar Ku Ceria" imageLink

我如何在 profileUser.ts 上调用它

console.log(this.userProvide.getUserEventData);

我现在希望在控制台上显示“Bandar Ku Ceria”,在提供者 user.ts 中,我是否使用正确的方式从 firestore 调用数据?帮助。

【问题讨论】:

    标签: typescript ionic-framework ionic3 google-cloud-firestore


    【解决方案1】:

    再次查看 Firestore 文档:https://firebase.google.com/docs/firestore/query-data/get-data

    您的语法似乎来自实时数据库,但情况发生了变化。

    你不能像在实时数据库中那样做 doc(users/id)。 你必须做 db.collection('users').doc(USER_ID).collection('events').doc('volunteer')

    如果您只想获取数据一次 .get().then()... 或者如果您需要实时更新

    .onSnapshot(snap => {
    //deal with the snapshot
    })
    

    【讨论】:

    • 您好,感谢您的回复,我对 ionic 比较陌生,.get.then 不起作用,.doc('volunteer').get().then() 在 .get 下有红色下划线
    • ionic 是 javascript,不是吗?所以 .get().then() 应该可以工作。 db.collection('users').doc(USER_ID).collection('events').doc('volunteer').get().then(snap => {//你有你的快照})
    猜你喜欢
    • 2017-02-08
    • 2020-06-06
    • 2019-11-23
    • 1970-01-01
    • 2020-09-19
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    相关资源
    最近更新 更多