0

I have been trying to dynamically insert an array of images and thumbnails into the js gallery but have been having trouble loading data via javascript. I have an array of images and thumbnails that I put in my array called imgArray. Cant seem insert the imgArray in the data array dynamically how the fotorama docs say to show my images in the gallery. Any help is greatly appreciated.

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
      ]
  });

1 Answer 1

1

Are you expecting something like this

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)

As per your code you are just creating an array of string instead of array of objects.

Sign up to request clarification or add additional context in comments.

1 Comment

Worked! Thank you so much for your help. Really appreciate it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.