【发布时间】:2018-02-25 01:20:22
【问题描述】:
我有一个包含 N 条路径的数组,用于从 firebase 数据库中的不同位置检索数据。
searchPaths = ['locations/date1/imageID', 'locations/date2/imageID2', locations/date3/imageID3, ...]
现在,我想遍历每个搜索路径并从中提取一个值以保存图像 URL 数组。
const searchPaths = ['locations/date1/imageID', 'locations/date2/imageID2']
const imageURLs = []
for(var Obj in searchPaths)
{
const path = Obj
admin.database().ref(path).once('value').then(snapshot =>
{
const URL = snapshot.val().fileURL;
imageURLs.push(URL);
console.log('ImageURL: ' + URL );
})
// here is where it gets sour
}.then(() => {
console.log("All image URL's" + imageURLs")
}
所以,我的问题是,当我们现在从每个 ref 中提取了我们需要的数据时,我该如何返回一个 Promise?有Promise.all 类型吗?去哪儿了?
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions