【问题标题】:Ionic +Firestore - bollean field RetrievingIonic +Firestore - 布尔字段检索
【发布时间】:2018-03-26 15:01:35
【问题描述】:

我需要检索 Document FIRESTORE 的 Boolean 的值

有人知道怎么做吗?

【问题讨论】:

    标签: angular typescript firebase ionic3 google-cloud-firestore


    【解决方案1】:

    希望你可以试试这个:

    使用Cloud Firestore SDK

    let docRef = db.collection("following").doc("your-id");
    
    docRef.get().then((doc)=> {
        if (doc.exists) {
            console.log("Document data:", doc.data());
            let myData=doc.data();
            let isTrue= myData.boolean-property-name;//return true or false
          } else {
            console.log("No such document!");
        }
    }).catch(function(error) {
        console.log("Error getting document:", error);
    });
    

    使用 AngularFire2: Docs

    注意:

    阅读这篇文章:Google Cloud Firestore integration with Ionic and AngularFire

    your-id - 你需要在这里传递你的doc

    boolean-property-name - 这只是一个假名。您需要在此处传递您的实际属性名称。你的情况就像cug.....

    【讨论】:

    • 您好,非常感谢您的回答...我尝试使用指定的代码,但是它返回了 3 个错误,打印在链接中:(drive.google.com/open?id=0B14jg18TLF3USC1xc292S3FYR0k)
    • 我现在进行了更改,我只收到 1 个错误:Typescript 错误属性 'get' 在类型 'AngularFirestoreDocument ' 上不存在。
    • 你在使用angularfire2吗?
    • 是的,我正在使用angularfire2
    • 好的...我会检查链接上的文档,我相信现在解决问题更容易了...您对我发送的代码帮助了我很多...谢谢寻求帮助! :)
    【解决方案2】:

    Firestore 不再支持直接 .get,请改用 doc.ref.get()。

    【讨论】:

      猜你喜欢
      • 2010-12-23
      • 2021-12-31
      • 2020-02-12
      • 2011-08-19
      • 2019-01-20
      • 1970-01-01
      • 2018-06-24
      • 2021-09-23
      • 2015-01-03
      相关资源
      最近更新 更多