swift - 从 autoID 节点中检索值
问题描述
我想从 autoID 节点中获取值。下面是我的结构:
"workout"
"exercise"
"Bench Press"
"(AutoIDNode)"
"reps: 10"
"set: 1"
"weight: 60"
如何获得“reps”、“set”和“weight”的值。
这是我的快速代码:
refSets.child("workout").child("exercise").child("Bench Press").observe(DataEventType.value, with: {(snapshot) in
if snapshot.childrenCount > 0 {
self.setsData.removeAll()
for sets in snapshot.children {
let snap = sets as! DataSnapshot
let key = snap.key
let value = snap.value
print(key)
print(value!)
}
}
})
我知道我缺少 .child("Bench Press") 之后的 autoID 节点的 .child() 路径。如何访问该节点?
提前致谢
解决方案
你可以试试
refSets.child("workout").child("exercise").child("Bench Press").observeSingleEvent(of: .value, with: {(snapshot) in
if let res = snapshot.value as? [String:[String:Int]] {
for item in Array(res.values) {
print(item["reps"])
}
}
})
推荐阅读
- python - 未关闭/不返回 python 守护程序线程是否会导致内存泄漏?
- sqlite - 如何在 SQLite 中将时间戳转换为日期?
- reactjs - 如何将自定义道具和主题与 Material-ui 样式的组件 API(Typescript)一起使用?
- c++ - 从 initializer_list 初始化向量会产生不明确的编译错误
- sql - 如何将记录插入表中 - 取决于另一个表的总 requiredQty?
- github - Github 操作/矩阵完成后运行作业
- python - 通过基于“_”拆分文本来替换熊猫列
- django-models - 在 Django 模型中添加带有 if-else 条件的 CALCULATED 字段
- javascript - Edge 中的 window.print() 是否发生了变化?
- spring - 为什么 Spring Cloud 数据流教程没有显示预期结果