2016-08-24 56 views
2

我正在使用名为redux-firebasev3的库来对Firebase进行三次独立的调用。如何在Firebase对象上设置多个属性?

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开发工具冻结并崩溃。有更好的方法我应该打这些电话吗?什么可能是失败的原因?由于开发工具崩溃,我看不到错误。

Here is the link to set function in the library.

回答

1

不知道如果我理解正确的,但你在找这个?

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

的例子是,我只是想制作三个电话的更好的方法的建议。它希望能加快速度并减少崩溃的可能性。 –

+0

这是否会覆盖对象上的其他属性。假设它有一个属性4,你不需要设置它。这次电话会不会只有三个属性? –

+0

由于[Firebase管道这些请求],您将通过合并调用获得的加速将最小化(http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network -app逐使用查询 - 代替-的-OBSE/35932786#35932786)。但更新将在电线上原子化,这意味着'attr1'无效(根据您的安全规则),整个'set()'在我的变体中将失败。 –

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" })

目标是具有库作为closley镜像the Firebase API作为可能的,包括事像设置和更新。

回购现在包括像simple example

相关问题