我考虑了这个结构,以便将数据写入Firebase服务器。然而,我在以这种方式编写结构的实际代码中遇到了复杂的问题。
我感到困惑的部分是获取autoID (-LETR-XJvQsZCOpG-T1N)作为all_images和all_plan_deatils节点的引用。我想不出写出这段代码的最好方法。任何建议都会有很大帮助。提前谢谢你
PlanIt
plans
-LETR-XJvQsZCOpG-T1N
Uid: "ZjtJdkjzuxc0mZn4u9TfWsXa9jh2"
date: "20180609"
title: "This weekend Plans?"
-UYijs09as9jiosdijfi
Uid: "some uid"
date: "20180609"
title: "some title"
all_images:
-LETR-XJvQsZCOpG-T1N
image_0: "https://img.evbuc.com/https%3A%2F%2Fcdn.evbuc.c.."
image_1: "https://img.evbuc.com/https%3A%2F%2Fcdn.evbuc.c.."
all_plan_details
-LETR-XJvQsZCOpG-T1N
detail_0: "Bike Rodeo, Safety Presentation and Riding Tour o"
detail_1: "Bike Rodeo, Safety Presentation and Riding Tour o"
这是我尝试更新节点的函数。我在这里的想法是-我首先将计划标题和UID设置为自动Id。然后,我尝试引用由自动ID创建的“键”,然后尝试存储all_images & all_dates,以引用由childByAutoID调用创建的相同键,然后更新这些值。
很抱歉代码中的任何混乱或混乱,我是字面上编辑的东西,因为我们说,所以某些名称和这样的可能会关闭,但我希望你能理解我仍然试图尝试的一般想法。
func uploadPlanitData(plan: [String], withDate: [String], withImage: [String], withTitle: String, forUID uid: String, sendComplete: @escaping (_ status: Bool) -> ()) {
_REF_PLANITS.childByAutoId().updateChildValues(["Planit Title" : withTitle, "uid": uid])
let key = _REF_PLANITS.key
let allImages = "all_images/\(key)/"
let allDates = "all_dates/\(key)"
let childUpdate = [allImages : withImage, allDates: withDate]
_REF_ALL_IMAGES.updateChildValues(childUpdate)
sendComplete(true)
}
UPDATE -该代码块当前的DB结构是这样的-这几乎是正确的-除了在all_images & all_dates节点内,而不是"planits“-我希望在那里有那个键(-LEaaZrwYI_SqonuREV9)。这样,我就可以将每个图像和日期与它们所属的计划唯一地组合在一起
Planit
Plans
-LEaaZrwYI_SqonuREV9
senderId
title:
all_dates
planits
0: ""
all_images
planits
0: ""
发布于 2018-06-10 09:41:52
如果我理解正确的话,您希望为新计划创建新密钥,然后将信息存储在具有相同密钥的其他节点中。如果是这样的话,它看起来就像这样:
let newPlanetRef = _REF_PLANITS.childByAutoId()
newPlanetRef.updateChildValues(["Planit Title" : withTitle, "uid": uid])
let key = newPlanetRef.key
let childUpdate = [allImages : withImage, allDates: withDate]
_REF_ALL_IMAGES.child(key).updateChildValues(childUpdate)
这里假设_REF_PLANITS
是/PlanIt/plans
的DatabaseReference
,_REF_ALL_IMAGES
是/PlanIt/all_images
的引用。
https://stackoverflow.com/questions/50778586
复制相似问题