Firebase - 多位置更新方法已弃用,现在怎么办?

时间:2017-06-08 20:13:06

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

我有一些使用多位置更新方法的应用程序如下:

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()并不是一个好主意,因为回滚会是一场噩梦。

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

1 个答案:

答案 0 :(得分:10)

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

const updates = {}; // this line is different
updates['/location1'] = data;
updates['/location2'] = data2;

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

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