本文介绍了使用异步/等待在firebase中运行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢Firebase 添加了对诺言的支持,是否可以在async
函数内部运行类似以下查询的方法?:
Appreciating that firebase has added support for promises, is there a way to run a query like the following inside of an async
function?:
const eventref = this.db.ref('cats/whiskers');
const value = await eventref.once('value')
运行以上命令返回对value
的承诺,我希望获取存储在cats/whiskers
的json blob.
Running the above returns a promise for value
, I'm hoping to get the json blob that is stored at cats/whiskers
.
推荐答案
value
的结果是快照,我们还需要执行1步来获取值.这应该像:
The result of value
is a snapshot, we need 1 more step to get the value. This should be like:
const eventref = this.db.ref('cats/whiskers');
const snapshot = await eventref.once('value');
const value = snapshot.val();
这篇关于使用异步/等待在firebase中运行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!