以编程方式在Firebase Realtime数据库中创建新路径? [英] Create new path in Firebase Realtime Database programmatically?

查看:47
本文介绍了以编程方式在Firebase Realtime数据库中创建新路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firebase文档中,我没有找到答案.如何在Javascript中以编程方式在实时数据库中添加新路径?像(只是一个例子):

In Firebase documentation I don't found the anweser. How to add a new path in real-time database programmatically in Javascript? Like (just an example):

标准路径: https://testapp.firebaseio.com/

在应用程序中,我想说些类似的话:如果是这样,请创建一个类似这样的路径: https://testapp.firebaseio.com/info/important/personal

And in the app I want to say something like: If this, then create a path like this: https://testapp.firebaseio.com/info/important/personal

推荐答案

将值写入Firebase数据库时,会自动在其中创建键和路径.因此,要生成路径info/important/personal,您需要在其下写一个值.例如:

Keys and paths in the Firebase Database are automatically created when you write a value to them. So to generate the path info/important/personal, you would write a value under it. For example:

firebase.database().ref('info/important/personal').set(true);

这将生成以下JSON:

This will generate the following JSON:

{
  "info": {
    "important": {
      "personal": true
    }
  }
}

请注意,相反情况也是如此:Firebase会自动删除空键/路径.因此,如果您删除上面的true,则整个JSON将被删除.

Note that the inverse is also true: Firebase will automatically remove empty keys/paths. So if you delete the true above, the entire JSON will be deleted.

这篇关于以编程方式在Firebase Realtime数据库中创建新路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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