javascript - Firebase how to find child knowing its id but not its parent's id (js)
问题描述
I have a firebase realtime database (not cloud) structure like:
users
kasdf872ajsda //user id
auiiq6d182g1 //list id
c: <mycontent> //list content
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;
});
解决方案
您可以先参考用户:var ref = firebase.database().ref('users');
然后循环:
ref.once('value').then((snapshot)=>{
snapshot.forEach(function(data) {
if (data.key == <YOUR_LIST_ID>) {
//you can access data.c here...
}
});
});
推荐阅读
- intellij-idea - IntelliJ - 语言级别 5 不支持菱形类型和 Lambda 表达式
- javascript - 如何使用 jquery 访问 $(this) 关键字下的子元素
- javascript - Webpack 热重载非常慢
- asp.net-mvc - 剑道 UI 多重网格
- javascript - Angular Firestore 根据返回的布尔值显示一个按钮,用于检查 Firestore 文档是否存在
- sql - 如何创建连接两个表的视图以显示一个表中的哪些实体未连接到另一个表中的实体?
- symfony - 如何在 Symfony3.4 中通过用户名使用 Lock 组件
- qt - 如何测量 QML 文件中的导入时间?
- amazon-ec2 - 如何调用具有变量的资源名称
- javascript - 无法在表格行上设置焦点