[英]How to retrieve data from different parent nodes in a Firebase Database in JavaScript
I have the following database:我有以下数据库:
I want to retrieve the value of name given a specific ID value in JavaScript.我想在 JavaScript 中检索给定特定 ID 值的 name 值。
Right now I have the following code, but it doesnt seem to acces both ID and name nodes:现在我有以下代码,但它似乎不能同时访问 ID 和名称节点:
var user = db.ref("Users").orderByChild("ID").equalTo("12345");
users.once("value").then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
...
This can be achieved with the code below:这可以通过以下代码实现:
var ref = db.ref("Users").orderByChild("ID/value").equalTo("12345");
ref.on("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
var name = childData.name.value;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.