gpt4 book ai didi

ios - 如何遍历并获取 firebase 中嵌套节点的所有键?

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:04 24 4
gpt4 key购买 nike

我正在尝试获取 Firebase 中嵌套节点的键,但我不确定如何执行此操作。

例如在这种情况下:

example

我怎么知道 2,3,4 存在于 1 中?

我正在考虑将一个值单独放入 firebase 的列表中。但是有没有更聪明的方法呢?有没有更有效的方法来获取 Firebase 中所有嵌套节点的键?

最佳答案

在安卓系统中

授予访问此快照的所有直接子级的权限。可以在原生 for 循环中使用:

for (DataSnapshot child : parent.getChildren()) { 
//Here you can access the child.getKey()
}

在 iOS 中

swift 3:

for (child in snapshot.children) { 
//Here you can access child.key
}

swift 4:

snapshot.children.forEach({ (child) in
<#code#>
})

在网络中

snapshot.forEach(function(childSnapshot) {
//Here you can access childSnapshot.key
});

您可以将它放在不同的列表或相同的路径中,重要的是要记住在调用事件时您真正检索了多少数据。以及您将如何查询该信息……这就是为什么在 NoSQL 中建议保留扁平节点的原因

关于ios - 如何遍历并获取 firebase 中嵌套节点的所有键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37606236/

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