javascript - 从 FIrebase 实时数据库中获取数据
问题描述
例如,这是我设置数据的方式:
var usersRef = firebase.database().ref("userlist/");
usersRef.child(nickname).set({
userid: id,
email: email,
});
如果我以后想收到给定昵称的电子邮件,我该怎么办?为什么我不能这样做:
const email =usersRef.child(nickname).child(email);
解决方案
要获取电子邮件,您需要执行以下操作:
var ref = firebase.database().ref("userlist").child(nickname);
ref.on("value", function(snapshot) {
let emails=snapshot.val().email;
console.log(email);
});
});
您需要引用该位置,然后将侦听器附加到它,以便能够检索子值,例如email
和id
推荐阅读
- objective-c - 有什么方法可以在 macOS 上获取系统定义目录的本地化显示名称?
- android - 片段堆栈管理
- python-3.x - python tkinter中的动态表单小部件交互
- java - 使用 junit 在 Gradle 中运行集成测试
- c# - 如何在 ASP.NET Core 中解析移动视图
- sql - 有没有办法通过 SQL 获取没有扩展名的文件名?
- git-log - 我正在尝试从 Grgit 日志中获取提交正文,这可能吗?
- python - Python 点击在帮助页面中显示模块版本
- c# - 实现相互使用的类型化接口的问题
- arrays - 如何在 ngFor 中将数组拆分为四个项目?