1
SETUP爲什麼在多個位置更新的行爲像SET而不是UPDATE?
在/demo/key
就像{a:1, b:2, c:3}
一個值。在/user/demo/key
有像true
var database = firebase.database();
var rootRef = database.ref();
方案A
rootRef.child('demo/key').update({a:0});
// Result -> {a:0, b:2, c:3}
// b and c not overwritten, still exist -> happy
// update() acts like I expected/read
方案B的值
var data = {a:7};
var updates = {};
updates[`/demo/${key}`] = data;
updates[`/user/demo/${key}`] = true;
rootRef.update(updates);
// Result -> {a:7}
// b:2, c:3 are gone -> Acts like set() ???
// Expected -> {a:7, b:2, c:3}
我不知道爲什麼這是......但我本來預計update()
函數將在任一實例中執行相同的操作並執行部分寫操作。
我做錯了什麼或缺少一個關鍵概念?
嗯。我明白你在說什麼。我想我的想法是,數據屬性會反映爲更具體的鍵。我可以做的是採取'數據= {a:7}'並動態生成更具體的更新引用,以免覆蓋。這是人們做的事嗎? – jmk2142
是的,這就是我會做的。 – cartant