亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

顯示 Firebase 存儲中的所有圖像(反應本機)

顯示 Firebase 存儲中的所有圖像(反應本機)

冉冉說 2023-09-28 15:44:26
我可以讓它顯示一張圖像,但進入一個文件夾并顯示所有圖像。我感覺我的映射是錯誤的。根據我的理解,.child()它指的是文件的名稱,但根據我的理解,它也可以指您要訪問的文件夾,并listAll()告訴它列出該文件的所有文件。    const [sampleImage, setSampleImage] = useState();     const getSampleImage = async () => {        const imageRef = firebase.storage().ref().child('Front/').listAll();        const url = await imageRef.getDownloadURL().catch((error) => { throw error });        setSampleImage(url);    }     useEffect(() => {        getSampleImage();    });  return (        { sampleImage && getSampleImage.map(Image => (                <View style={{ justifyContent: 'center' }} key={imageRef.id}>                    <Image source={{ uri: sampleImage.get(k) }} style={{ width: 350, height: 350 }} />                 </View>                ))}    ); }
查看完整描述

1 回答

?
慕村9548890

TA貢獻1884條經驗 獲得超4個贊

API返回一個 a 的承諾,其中包含一個項目列表listAll(),因此您需要等待該列表,循環該列表,然后調用每個項目。ListResultStorageReferencegetDownloadURL()


就像是:


const getSampleImage = async () => {

? ? const imageRefs = await firebase.storage().ref().child('Front/').listAll();

? ? const urls = await Promise.all(imageRefs.items.map((ref) => ref.getDownloadURL());

? ? setSampleImage(urls);

}

進而:


{ sampleImage && getSampleImage().map(url => (

? ? <View style={{ justifyContent: 'center' }} key={imageRef.id}>

? ? ? ? <Image source={{ uri: url }} style={{ width: 350, height: 350 }} />?

? ? </View>

))}




查看完整回答
反對 回復 2023-09-28
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號