由于某些原因,我的firebase数据库中的文本字段为空...我没有得到我的用户输入。使用firebase的第一天,我可能错过了一些简单的事情......
var tickets = [Ticket]()
func test() {
let ref = FIRDatabase.database().reference().child("tickets")
let childRef = ref.childByAutoId()
guard let Price = emailTextField.text, ticketName = passwordTextField.text else {
print("Form is not valid")
return
}
let values: [String: AnyObject] = ["Price": Price, "ticketName": ticketName]
ref.observeEventType(.ChildAdded, withBlock: { (snapshot) in
let ticketId = snapshot.key
let ticksRef = FIRDatabase.database().reference().child("tickets").child(ticketId)
ticksRef.observeSingleEventOfType(.Value, withBlock: { (snapshot) in
guard let dictionary = snapshot.value as? [String: AnyObject] else {
return
}
self.messages.append(Ticket(dictionary: dictionary))
childRef.updateChildValues(values) { (error, ref) in
if error != nil {
print(error)
return
}
}
答案 0 :(得分:0)
我意识到我的函数在用户将任何内容写入文本字段之前被调用,这就是我的数据库没有得到用户输入的原因。