我在 Firebase 中的数据库目前看起来像这样:
locations: {
person: ""
location: ""
}
如何嵌套数据,使其看起来像这样:
locations: {
person: "" {
location: ""
}
}
一种结构,其中 locations 是父级,person 是子级,location 是 person 的子级。
我知道这些关系,我只是不太确定语法。
这是我目前使用 Swift 编写的代码:
let locRef = locationRef.childByAutoId()
let locItem = [
"location": getLocation(),
"person": senderId
]
locRef.setValue(locItem)
谢谢。
最佳答案
let locRef = locationRef.childByAutoId()
let locItem = [
senderId : [
"location": getLocationID()
]
]
SenderID 将是这个人的关键,所以你可以通过它的 ID 找到这个人......并且这个 ID 包含一个嵌套的位置键
您只需要逻辑吗?或者您需要工作代码示例吗?
关于swift - 如何在 Firebase 实时数据库中嵌套数据 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38037749/