通过 Firebase Admin 访问深度数据

Access to Deep data via Firebase Admin

如何通过 Firebase Admin 访问深层数据?

数据:

{
    "keyboards": {
        "StartKeyboard": [
            "KeyboardA",
            "KeyboardB",
            "KeyboardC"
        ],
        "SecendKeyboard": {
            "parent": "StartKeyboard",
            "childs": [      //*** I need to get this childs: [] ***
                "Keyboard1",
                "Keyboard2",
                "Keyboard3"
            ]
        }
    }
}

当我使用下面的代码时,我在输出中有所有数据

const ref = db.ref('/');    All Data
ref.on("value", function (snapshot) {
    console.log(snapshot.val());
  });

当我使用下面的代码时,我在输出中有 keyboards 的孩子

 const ref = db.ref('keyboards');   // inside of Keyboards
    ref.on("value", function (snapshot) {
        console.log(snapshot.val());
      });

但我不知道如何获得 childs of SecendKeyboard/childs。 我的意思是 Keyboard1Keyboard2Keyboard3 的数组。 谢谢。

获取键盘子元素:

const ref = db.ref('keyboards/SecendKeyboard/childs');
ref.on("value", function (snapshot) {
    console.log(snapshot.val());
});

或者:

const ref = db.ref('keyboards/SecendKeyboard');
ref.on("value", function (snapshot) {
    console.log(snapshot.child("childs").val());
});

或者

const ref = db.ref('keyboards');
ref.on("value", function (snapshot) {
    snapshot.forEach(function(childSnapshot) {
        console.log(snapshot.val()); // prints StartKeyboard and SecendKeyboard
        if (snapshot.child("SecendKeyboard").exists()) {
            console.log(snapshot.child("SecendKeyboard").val());
        }
    })
});