Firebase Web update()删除所有其他子节点 [英] Firebase Web update() deletes all other child nodes
问题描述
大家好,我在这里变得很奇怪.当用户单击按钮时,我尝试更新一个特定的子节点.这是我的代码:
Hello everyone I am getting weird behaviour here. I try to update one specific child node, when the user clicks a button. Here is my code:
var updates2 = {};
var offer = {
minusAccandShare: 2,
}
updates2['/offerLight/' + keyReal] = offer;
updates2['/offer/' + keyReal] = offer;
return firebase.database().ref().update(updates2);
一切正常,更新了正确的节点,但是在更新minusAccandShare时,其他所有内容都会被删除
Everything is working fine the correct nodes are updated but while updating minusAccandShare everything else will be deleted
结构类似于:
offer
jifdjsiavdas
minusAccandShare: -6
offerName: "Replacement"
offerText: "You have the choice to..."
...
它变成
offer
jifdjsiavdas
minusAccandShare: 2
我多次使用了这种方法,就像在Firebase指南中描述的那样,它始终像一种魅力一样起作用.但是在那里,我用新的密钥创建了完全新的节点,因此没有什么可以删除.
I used this approach like described in the firebase guides multiple times and it always worked like a charm. But there I created completly new nodes with a new key so there was nothing to be deleted.
谢谢大家:D
推荐答案
代码中实际发生的是以下情况:
What is actually happening in your code is the folowing:
您正在完全写入密钥,从而清除了数据集中的所有属性.
You are writing entirely to the key thereby wiping off the whole properties in your dataset.
此
updates2['/offer/' + keyReal] = offer;
清除该特定密钥中的全部数据.
wipes out the whole data in that particular key.
尝试以下方法:
firebase.database().ref('offer/' + keyReal).update({
minusAccandShare: 2,
});
这可让您确保更改Firebase数据集中的指定属性.
this allows you to make sure you change the specified property in your firebase dataset.
我希望这对您有帮助
这篇关于Firebase Web update()删除所有其他子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!