【问题标题】:No data at node callback in Firebase Realtime Database? [duplicate]Firebase 实时数据库的节点回调中没有数据? [复制]
【发布时间】:2019-03-20 14:31:53
【问题描述】:

我正在尝试找到一种方法来处理 DB 状态(零状态)中的任何数据。

我的代码是:

Database.database()
    .reference(withPath: "My_Path")
    .child("My_Inner_Path")
    .observeSingleEvent(of: .value) { (snapshot) in
        // Callback with data at the observing node.
}

但如果节点为空或尚不存在,则上述代码不会被回调。我需要这样做,以便我可以隐藏我的指标并显示零状态或触发一些其他方法以在节点状态下没有数据。提前致谢。

【问题讨论】:

  • 确实如此。非常感谢弗拉德。
  • np。祝你有美好的一天

标签: ios swift firebase firebase-realtime-database


【解决方案1】:

以下是我在Swift的问题的解决方案。

Database.database()
.reference(withPath: "My_Path")
.child("My_Inner_Path")
.observeSingleEvent(of: .value) { (snapshot) in
    guard snapshot.exists() else {
        // The node doesn't exist.
        return
    }
    // OR
    guard snapshot.childrenCount != 0 else {
        // No children exist.
        return
    }    
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2021-09-24
    • 2023-01-16
    • 1970-01-01
    • 2019-10-11
    相关资源
    最近更新 更多