javascript - 对 Firebase 存储数据进行排序 (Vue)
问题描述
我正在从我的 firebase 存储中检索一些图像(仅限 URL)。
这很好用
async loadStoragePictures(){
fb.storage.ref('images/products').listAll().then(snap => {
const imageUrlArray: any = []
snap.items.forEach(itemRef => {
itemRef.getDownloadURL().then(imgUrl => {
imageUrlArray.push(imgUrl)
})
})
store.commit('setPictures', imageUrlArray)
})
},
不幸的是,我想按上次更改日期对这些 URL 进行排序。
添加.sort(by: { $0.name > $1.name })
(或等效的lastAction)我在快速帮助中看到的方式不起作用。
那么我怎样才能让我的数据snap.items
得到排序呢?
解决方案
只需在提交之前添加一个排序:
async loadStoragePictures(){
fb.storage.ref('images/products').listAll().then(snap => {
const imageUrlArray: any = []
const myItems = snap.items.sort((a, b) => {
return a.name.localeCompare(b.name);
});
myItems.forEach(itemRef => {
itemRef.getDownloadURL().then(imgUrl => {
imageUrlArray.push(imgUrl)
})
})
store.commit('setPictures', imageUrlArray)
})
},
推荐阅读
- dependency-injection - 通过方法获取 TypeLiterals 以减少冗长
- python - 如何更改我的固定变量之一以成为时间相关的?
- python - 如何将while循环代码转换为for循环
- nuxt.js - 如何在创建计时器中使用 setInterval
- javascript - 如何从 console.log() 获取有用的信息
- android - 名称仅包含数字的变量(kotlin/android)
- nginx - Nginx - 在我应用 SSL 证书后得到 403 禁止
- javascript - 在 MongoDB 或 JavaScript 中使用递归和遍历技术的嵌套集合树视图数据结构
- python - 如何在 Python3 中正确搜索并获取值?
- python - Python vs matplotlib - 图表生成问题