如何将新项添加到firebase

时间:2021-03-23 07:33:25

I want to add a new item to my list, I use firebase without user(email,password)

我想在我的列表中添加一个新项目,我使用没有用户的firebase(电子邮件,密码)

I want to add new items like this:-

我想添加这样的新项目: -

list
-vdjs43ndjufd87
         "name" : Jak
         "university" : Harvard



list
-vdjs43ndjufd87
          "name" : Jak
          "university" : Harvard
          "age" : 23

this code is not working with me:-

这段代码不适合我: -

let key = ref.child("posts").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)`h

1 个解决方案

#1


0  

All you need to do is this:

你需要做的就是:

let post = ["uid": userID,
    "author": username,
    "title": title,
    "body": body]  

ref.child("posts").childByAutoId().setValue(post)

#1


0  

All you need to do is this:

你需要做的就是:

let post = ["uid": userID,
    "author": username,
    "title": title,
    "body": body]  

ref.child("posts").childByAutoId().setValue(post)