2016-08-24 58 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

相關問題