Firebase 如何更新多个 children?

Firebase How to update multiple children?

我有 parent 和很多 children 这样的:

 Parent:{
        "childe1":"data",
        "childe2":"data",
        "childe3":"data",
        "childe4":"data",
        "childe5":"data"
 }

我怎样才能同时更新 children [ childe1 , childe2 , childe3 ],防止任何其他用户同时更新它们?

要同时更新多个属性,您可以运行 update() 调用:

ref.child("Parent").update({
  childe1: "newdata",
  childe2: "newdata",
  childe3: "newdata"
});

您甚至可以将路径指定为键,以防属性在树中处于不同级别。尽管这里似乎不是这种情况,但语法是:

ref.update({
  "Parent/childe1": "newdata",
  "Parent/childe2": "newdata",
  "Parent/childe3": "newdata"
});

确切的验证有点取决于您希望允许的内容,但通常您会 write .validate rules on the server that validate that newData meet your requirements