gpt4 book ai didi

ios - 来自 Firebase 的复杂查询

转载 作者:行者123 更新时间:2023-11-28 16:05:38 25 4
gpt4 key购买 nike

我需要从 Firebase 连接我的两个表。现在,我得到了如下所示的数据结构。

当用户创建日志时,它会从 Firebase 获得一个唯一 ID。此 ID 保存在创建它的用户 (test2@test.dk) 下。

但我想显示日志,只显示给登录的用户,我该如何实现?现在,我只能获取 key ,但我需要持续时间和开始日期等数据。

logs
-KVMbJKN1i2vAxzutiYq
duration: 14
startDate: 28/10/2016

-KVMbLL4i_9dwaRZ9REB
duration: 28
startDate: 01/09/2016

-KVMiLwoSY34TZpf8mST
duration: 14
startDate: 2/2/2016

users
Edl7nDpJWIdNmDVUDn87p31d9mN2
email: test@test.dk
firstName: test
imageUrl: URL
lastName: test
provider: Facebook

KX6DRd0k5fasEaqB8vJWiXkp69L2
email: test1@test.dk
firstName: test1
imageUrl: URL
lastName: test1
provider: Firebase

WRgxyjSpQlUPmeJwfF9I7PhpvHs1
email: test2@test.dk
firstName: test2
imageUrl: URL
lastName: test2
logs
-KVMbJKN1i2vAxzutiYq: true
-KVMbLL4i_9dwaRZ9REB: true
-KVMiLwoSY34TZpf8mST: true
provider: Firebase

最佳答案

要获取 duration startDate ,只需将其查询到特定节点的所需位置:-

FIRDatabase.database().reference().child("user/\(FIRAuth.auth()!.currentUser!.uid)/logs").observeSingleEvent(of: .value, with: {(userSnap) in 

if let SnapDict = userSnap.value as? [String:AnyObject]{

for each in SnapDict{

FIRDatabase.database().reference().child("logs/\(each.key)").observeSingleEvent(of: .value , with : {(Snap) in

print(Snap.value)

})
}
}
})

关于ios - 来自 Firebase 的复杂查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40346907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com