繁体   English   中英

对 Firebase 存储数据进行排序 (Vue)

[英]Sort Firebase Storage data (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)
      })
    },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM