輸入以下代碼后,我會收到 /Images 檔案夾中兩個不同影像的兩個不同 URL。我希望顯示這兩個,但似乎無法在平面串列中這樣做。這是我的檢索代碼,歡迎提出任何關于從 Firebase 存盤中顯示影像的建議。
async function fetchPictures() {
await firebase.storage().ref().child('Images').list().then(result => {
// Loop over each item
result.items.forEach(pics => {
firebase.storage().ref().child(pics.fullPath).getDownloadURL().then((url) => {
setUrl(url);
})
});
})
}
uj5u.com熱心網友回復:
將您的狀態更改為 imageUrl 陣列而不是單個 url:
const [images, setImages] = useState([]);
然后在獲得結果時推送到該陣列:
await firebase.storage().ref().child('Images').list().then(result => {
// Loop over each item
const imageUrls = [];
result.items.forEach(pics => {
firebase.storage().ref().child(pics.fullPath).getDownloadURL().then((url) => {
imageUrls.push(url);
})
});
setImages(imageUrls);
});
然后應該很容易將它們顯示在您的 FlatList (使用images狀態)中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/416526.html
標籤:
下一篇:部署Firebase功能客戶端
