因此,在我的应用程序中,用户将数据输入到已保存并存储在我的 firebase 数据库中的文本字段中。但是当输入改变时,它完全覆盖了我之前在数据库中的内容。
这是代码;
@IBAction func cont(_ sender: UIButton) {
// Database reference
ref = Database.database().reference()
//Referencing the actual table the data is updated and stored in
let customerRef = ref.child("customerDetails")
customerRef.updateChildValues(["email": emailTextField.text!])
customerRef.updateChildValues(["firstName" : firstNTextField.text!])
}
这是我的数据库的图像;
将收集多个数据,我将添加更多字段,例如姓氏和其他内容。那么现有数据如何才能不受影响呢?
最佳答案
使用此功能,您可以将列表添加到数据库的 customerDetails 内部,而不会影响任何现有数据。另外,您可以像这样在一行中更新您的值:
let ref = Database.database().reference()
let customerRef = ref.child("customerDetails").childByAutoId()
customerRef.updateChildValues(["email": emailTextField.text!,
"firstName": firstNTextField.text!])
关于ios - 如何在 Swift 和 Firebase 中更新数据而不影响现有数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49260381/