我一直在嘗試將一組影像和縮略圖動態插入到 js 庫中,但在通過 javascript 加載資料時遇到了問題。我有一組影像和縮略圖,我將它們放入名為 imgArray 的陣列中。似乎無法動態地將 imgArray 插入資料陣列中,fotorama 檔案如何在圖庫中顯示我的影像。任何幫助是極大的贊賞。
https://fotorama.io/docs/4/initialization/
var imgArray = [];
for ( img in images ) {
imgArray.push('{img:"' images[img].medium '", thumb:"' images[img].medium '"}');
}
/* imgArray now has below data
{img:"https://dl5zpyw5k3jeb.cloudfront.net/photos/pets/56517207/1/?bust=1659229627&width=300", thumb:"https://dl5zpyw5k3jeb.cloudfront.net/photos/pets/56517207/1/?bust=1659229627&width=300"},
{img:"https://dl5zpyw5k3jeb.cloudfront.net/photos/pets/56517207/2/?bust=1659229629&width=300", thumb:"https://dl5zpyw5k3jeb.cloudfront.net/photos/pets/56517207/2/?bust=1659229629&width=300"}
*/
$('.fotorama').fotorama({
data: [
//Need to get imgArray in here
]
});
uj5u.com熱心網友回復:
你期待這樣的事情嗎
var imgArray = [];
let images = {family:
{
medium:'medium',
thumb:'thumb'
},
employ:{
medium:'medium',
thumb:'thumb'
}
};
for ( img in images ) {
//Checks if object has any pptys
if(Object.keys(images[img]).length){
imgArray.push({img: images[img].medium , thumb: images[img].thumb});
}
}
$('.fotorama').fotorama({
data: imgArray
});
console.log(imgArray)
根據您的代碼,您只是創建一個字串陣列而不是物件陣列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/531056.html
