2016-12-05 104 views
1

如何將數據追加到Firebase中的節點?值更新只是一個字符串,而不是字典。Firebase將數據追加到節點

Firebase應該能夠增加每個項目。我認爲update會工作,但只會更新字典。當我嘗試設置值時,它會擦除​​所有內容。

FIRDatabase().reference().database.childRef(refUrl: path).updateChildValues([:]) 

實施例:

node{ 
     1:itemOne 
     2:itemTwo 
     3:itemThree 
} 

回答

1

從火力文檔

https://firebase.google.com/docs/database/ios/read-and-write

Update specific fields To simultaneously write to specific children of a node without overwriting other child nodes, use the updateChildValues method.

試somethi ng like

let key = ref.child("node").childByAutoId().key 
let post = ["uid": userID, 
      "author": username, 
      "title": title, 
      "body": body] 
let childUpdates = ["/posts/\(key)": post, 
        "/user-posts/\(userID)/\(key)/": post] 
ref.updateChildValues(childUpdates)