[英]How can I write multiple data to firebase?
I have a problem about writing multiple data to firebase.我在将多个数据写入 firebase 时遇到问题。 I have three different arrays, one int and I have to take uid's child(adress) and uid's name.
我有三个不同的 arrays,一个 int,我必须取 uid 的孩子(地址)和 uid 的名字。 In simple way I want to make orders node and I have to write all these datas in same node.
以简单的方式,我想创建订单节点,并且必须将所有这些数据写入同一个节点。 I tried to make it set value but it takes only the last one other will deleted.
我试图让它设置值,但它只需要最后一个将被删除。 I can't find any way to fix it.
我找不到任何方法来解决它。 How can I solve?
我该如何解决?
Here my code:这是我的代码:
func firebaseConfigForUserAndAdress() {
guard let uid = Auth.auth().currentUser?.uid else { return }
// these are my arrays
print(siparisEdilenUrunleriTutanArray)
print(siparisEdilenFiyatlariTutanArray)
print(siparisEdilenCountlariTutanArray)
// values for only try...
var values = siparisEdilenUrunleriTutanArray + siparisEdilenFiyatlariTutanArray
let refOrder = Database.database().reference().child("orders").child("kullanicilar").child(uid)
refOrder.setValue(values, withCompletionBlock: { (error, ref) in
if let error = error {
print("Failed to update database values with error: ", error.localizedDescription)
return
}
//self.dismiss(animated: true, completion: nil)
})
refOrder.setValue(["urun sayilari" : self.siparisEdilenCountlariTutanArray])
}
How can I write these datas to firebase?如何将这些数据写入 firebase?
I'm not sure I understand correctly, but think you may be looking for childByAutoId()
.我不确定我是否理解正确,但认为您可能正在寻找
childByAutoId()
。 When you call childByAutoId()
on a location, Firebase will generate a unique ID under that location where you can then write the data.当您在某个位置调用
childByAutoId()
时,Firebase 将在该位置下生成一个唯一 ID,然后您可以在其中写入数据。
For you that'd look something like:对你来说,这看起来像:
let refOrder = Database.database().reference().child("orders").child("kullanicilar").child(uid)
refOrder.childByAutoId().setValue(values, withCompletionBlock: { (error, ref) in
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.