如何在firebase对象上设置多个属性?

时间:2016-08-24 14:49:31

标签: javascript reactjs firebase redux firebase-realtime-database

我正在使用名为redux-firebasev3的库对firebase进行三次单独的set调用。

for(let object of array) {
    ....
    firebase.set(`/object/${id}/attr1`, attr1);
    firebase.set(`/object/${id}/attr2`, attr2);
    firebase.set(`/object/${id}/attr3`, attr3);
}

数组的长度为32.当它到达最后一个对象的第8个时,chrome dev工具会冻结并崩溃。我有更好的方式来打电话吗?失败的原因是什么?由于开发工具崩溃,我无法看到错误。

Here is the link to set function in the library.

2 个答案:

答案 0 :(得分:1)

不确定我是否理解正确,但你在找这个吗?

firebase.set(`/object/${id}`, { attr1: attr1, , attr2: attr2, attr3: attr3 });

答案 1 :(得分:0)

免责声明:我是redux-firebasev3

的作者之一

不确定我是否理解原始问题,但要澄清:

一次在一个对象中设置多个属性:

firebase.set(`/object/${id}`, { attr1: "some val", attr2: "some string", attr3: "some other" });

要将多个属性设置为多个单独的位置:

firebase.set(`/messages/${id}`, { attr1: "some val", attr2: "some string" }) firebase.set(`/objects/${id}`, { attr1: "some val", attr2: "some string" })

设置更新现有路径

firebase.update(`/messages/${id}`, { attr1: "some val", attr2: "some string" })

目标是尽可能将库作为最后镜像the Firebase API,包括设置和更新等内容。

现在,repo包含simple example

等示例