小编Ben*_*ene的帖子

Firebase更新与设置

正如标题所说,我不能得到之间的区别updateset.此外,文档无法帮助我,因为如果我使用set,更新示例的工作原理完全相同.

update来自文档的示例:

function writeNewPost(uid, username, title, body) {

    var postData = {
        author: username,
        uid: uid,
        body: body,
        title: title,
        starCount: 0
    };

    var newPostKey = firebase.database().ref().child('posts').push().key;

    var updates = {};
    updates['/posts/' + newPostKey] = postData;
    updates['/user-posts/' + uid + '/' + newPostKey] = postData;

    return firebase.database().ref().update(updates);
}
Run Code Online (Sandbox Code Playgroud)

使用相同的例子 set

function writeNewPost(uid, username, title, body) {

    var postData = {
        author: username,
        uid: uid,
        body: body,
        title: title,
        starCount: 0
    };

    var newPostKey = firebase.database().ref().child('posts').push().key; …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-realtime-database

66
推荐指数
1
解决办法
5万
查看次数