如何在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);