【问题标题】:Firebase - Multi-location updates method deprecated, what now?Firebase - 不推荐使用多位置更新方法,现在怎么办?
【发布时间】:2017-06-08 20:13:06
【问题描述】:

我有一些应用程序使用了多位置更新方法,如下所示:

const updates = [];
updates['/location1'] = data;
updates['/location2'] = data2;

firebase.database().ref().update(updates);

然而,当我正在开发一个新应用时,我收到了以下消息:

FIREBASE WARNING: Passing an Array to Firebase.update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.

没有关于如何在任何地方执行多位置原子更新的真实信息,文档仍然使用旧方法。链接then() 不是一个好主意,因为回滚将是一场噩梦。

关于新的多地点更新方法的任何线索和/或信息?

【问题讨论】:

    标签: javascript firebase firebase-realtime-database ecmascript-6


    【解决方案1】:

    我什至不知道你可以传递一个数组。你应该传递一个对象:

    const updates = {}; // this line is different
    updates['/location1'] = data;
    updates['/location2'] = data2;
    
    firebase.database().ref().update(updates);
    

    我们用于设置属性的数组语法也适用于 JavaScript 对象。

    【讨论】:

    • 好吧,我现在觉得有点愚蠢。感谢您的快速回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多