Firebase 如何更新多个孩子? [英] Firebase How to update multiple children?

查看:21
本文介绍了Firebase 如何更新多个孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的父母有很多这样的孩子:

I have parent with many children like this:

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

如何同时更新孩子 [ childe1 , childe2 , childe3 ] 以防止任何其他用户同时更新它们?

How can I update the children [ childe1 , childe2 , childe3 ] at same time, preventing any other user from updating them at same time?

推荐答案

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

To update multiple properties at the same time, you can run an update() call:

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

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

You can even specify paths as the keys, in case the properties are at different levels in the tree. Even though that doesn't seem to be the case here, the syntax would be:

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

确切的验证在一定程度上取决于您希望允许的内容,但通常您会在服务器上编写 .validate 规则以验证 newData 是否满足您的要求.

The exact validation depends a bit on what you'd like to allow, but in general you'd write .validate rules on the server that validate that newData meet your requirements.

这篇关于Firebase 如何更新多个孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆