【问题标题】:Failure reading data out of document using Firestore使用 Firestore 从文档中读取数据失败
【发布时间】:2018-02-27 17:41:10
【问题描述】:

我将 Ionic 3 与 Firestore 和 AngulareFire2/5 一起使用,但在从我的文档中获取数据时遇到了一些问题。

async getLocalisation() {
  const localisation = await this.afs.doc(`/localisation/France/`)
    .ref
    .get()
    .then(data => console.log(data.data));
}

控制台正在显示实际的数据原型:

DocumentSnapshot.prototype.data = function () {
    validateExactNumberOfArgs('DocumentSnapshot.data', arguments, 0);
    if (!this._document) {
        throw new FirestoreError(Code.NOT_FOUND, "This document doesn't exist. Check doc.exists to make sure " +
            'the document exists before calling doc.data().');
    }
    return this.convertObject(this._document.data);
};

我如何在不使用 valueChanges() 的情况下获取我的数据,因为我的数据根本不会更新? 谢谢

【问题讨论】:

    标签: javascript ionic3 google-cloud-firestore angularfire2


    【解决方案1】:

    好的,我已经设法解决了我的问题,我想我对此感到厌倦了。 data 是方法而不是属性,我只需要执行方法即可。

    async getLocalisation() {
      const ref = await this.afs.doc(`/localisation/France/`).ref;
      const result = await ref.get();
      console.log(result.data());
    }
    

    【讨论】:

      猜你喜欢
      • 2023-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多