更新孩子的价值

时间:2018-05-22 17:55:49

标签: swift database firebase firebase-realtime-database

当我的代码为:

时,如何更新子值( ID
let usersDatabaseRef = Database.database().reference().child("usersDatabase").child(userID).child("Customers")
    usersDatabaseRef.observe(.value, with: { snapshot in
        for child in snapshot.children {
            let childSnap = child as! DataSnapshot
            let userCustomerSnap = childSnap
            for customer in userCustomerSnap.children.allObjects as! [DataSnapshot] {
                let customerSnap = customer
                let dict = customerSnap.value as! [String: Any]
                let id = dict["ID"]
                let employee = dict["Assigned employee"]

                let myService = ServiceModel(id: id as? String, employee: employee as? String)
                self.serviceList.append(myService)
            }
            self.tableViewService.reloadData()

我的代码有效但修改后效果不佳。 下面是我现有的更新值的代码,但我怎么说 - 现在不工作。

func updateService(id:String) {
    ref = Database.database().reference().child("usersDatabase").child(userID).child("Customers")
    let serviceStatus = ["ID": id
    ]
    ref.child(id).updateChildValues(serviceStatus)
}

0 个答案:

没有答案