我想从 autoID 节点中获取值。以下是我的结构:
"workout"
"exercise"
"Bench Press"
"(AutoIDNode)"
"reps: 10"
"set: 1"
"weight: 60"
如何获取“次数”、“组数”和“重量”的值。
这是我的快速代码:
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"])
}
}
})
关于swift - 从 autoID 节点中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55814594/