Firebase如何找到知道其ID但不知道其父母ID(JS)的孩子 [英] Firebase how to find child knowing its id but not its parent's id (js)
问题描述
我有一个Firebase实时数据库(非云)结构,例如:
I have a firebase realtime database (not cloud) structure like:
users
kasdf872ajsda //user id
auiiq6d182g1 //list id
c: <mycontent> //list content
我知道列表ID(在这种情况下 auiiq6d182g1
),我想检索< mycontent>
,但我不知道用户ID kasdf872ajsda
,因为我要检索的内容可能不是来自当前正在使用该网站的用户的(事实上,我没有为读取设置任何数据库规则,仅对于写入才正确吗?)。
i know the list id (in this case auiiq6d182g1
) and i want to retrieve <mycontent>
, but i don't know the user id kasdf872ajsda
, because what i'm going to retrieve is probably not from the user currently using the website (and i'm not setting any database rules for "read" in fact, only for "write" is that correct?).
我现在正在做的事情(不起作用):
What i'm doing right now is this (not working):
var ref = firebase.database().ref().child('users');
ref.child(listID).once("value", function(snapshot) {
var snap = snapshot.val();
myContent = snap.c;
});
推荐答案
找到解决方案,如果有人遇到同样的问题:
Found the solution, if someone should encounter the same issue:
ref.once("value", function(snapshot) {
snapshot.forEach(function(data) {
snap = data.child(<YOUR_LIST_ID>).child('c').val();
if (snap != null){
myContent = snap;
}
});
});
还 ref
与每个人所说的相反
var ref = firebase.database().ref().child('users');
这不起作用:
var ref = firebase.database().ref('users');
这篇关于Firebase如何找到知道其ID但不知道其父母ID(JS)的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!