如何在firebase中添加元素数组? [英] How to add array of elements in firebase?

查看:148
本文介绍了如何在firebase中添加元素数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何简单地将数据从数组存储到Firebase。让我们考虑一下,我有一个元素数组。

I want know how to simply store the data from the array to firebase. Let us consider that I having an array of element.

function Something() {
    var elements=new Array()
    elements[0]=10;
    elements[1]=20;
    elements[2]=30;

    database = firebase.database();
    var ref = database.ref('ExTable');
    ref.set(elements);
}

ref.set(elements); 函数会将数据保存到我的Firebase数据库中?

Will the ref.set(elements); function will save the data to my firebase DB?

现在,此数组包含三个值,我如何将它们作为任何父节点下面的节点存储到Firebase。像

Now this array contains three values, and how can I store them to firebase as nodes below any parent node. Like

+---Parent
      |
      |
      +---0
      |   |
      |   |
      |   +---10
      |
      |
      +---1
      |   |
      |   |
      |   +---20
      |
      |
      +---2
          |
          |
          +---10

我想像上面的示例一样存储它们。因为我的数组有时包含各种数量的元素。

I want to store them as like in the above example. Because my array sometimes contains various number of elements.

推荐答案

只需将其传递给对象数组,如下所示。

Just pass it with array of objects like shown below.

var array = [];

array.push({"name":"Barry"});
array.push({"name":"Allen"});

ref.push(array);

这篇关于如何在firebase中添加元素数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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