How to dymanically load gallery items from dataset?

Dear memebers, could somebody assist me? I tried different approaches to fill the gallery items, but haven’t been successfull yet. Probably (hopefully) it is something simple I missed…
Thank you in advance for your help/tips.
Sarah


$w.onReady( function () {
$w(‘#dynamicDataset’).onReady(() => {
let vastgoedItem = $w(‘#dynamicDataset’).getCurrentItem();
$w(“#text36”).text = toonAdres(vastgoedItem.adresStraat, vastgoedItem.adresPostcode, vastgoedItem.adresPlaats);
$w(“#text34”).text = toonPrijs(vastgoedItem.prijs);
});

$w('#gallery1').items = []; 
$w('#dataset1').onReady(() => { 
    $w('#dataset1').getItems(0,20) 
        .then( (result) => { 

let ItemsData = result.items;
let galleryItems = $w(‘#gallery1’).items;
for ( var i = 0; i < ItemsData.length; i++) {
let DataItem = ItemsData[i];
//let galleryItem = [];
galleryItems.items[i].id = i;
galleryItems.items[i].src = DataItem.afbeelding;
galleryItems.items[i].title = DataItem.title;
galleryItems.items[i].link = DataItem.url;

/*
galleryItem = “"src":"” + DataItem.afbeelding + “"”;
if (DataItem.title) {
galleryItem = galleryItem + “, "title":” + DataItem.title + “"”;
}
if (DataItem.url) {
galleryItem = galleryItem + “, "link":"” + DataItem.url + “"”;
}
galleryItems.item[i] = galleryItem;
console.log(galleryItem);
*/
}
console.log(galleryItems);
$w(“#gallery1”).items = galleryItems;

//0: “{"galleryItem":"\"src\":\"wix:image://v1/50f021_2c2909b8dacb4e5b82d073a6e16d6e91~mv2.jpg/350_200/albanberg3%5B1%5D.jpg\", \"title\":\"Albanberg3\""}”
//1: “{"galleryItem":"\"src\":\"wix:image://v1/50f021_fa6a4526c3e44e179d5b574d8820a256~mv2.jpg/350_200/albanberg2%5B1%5D.jpg\", \"title\":\"Albanberg2\""}”
//2: “{"galleryItem":"\"src\":\"wix:image://v1/50f021_eb975d2f0f8c42e2bb76ee613d377f13~mv2.jpg/350_200/albanberg1%5B1%5D.jpg\", \"title\":\"Albanberg1\""}”
} )
. catch ( (err) => {
let errMsg = err.message;
let errCode = err.code;
console.log(errCode + " : " + errMsg);
});
});
});

Hello

Here’s how u can do it, get the results array corresponding to this specific dynamic page using query then for each item of the results push the image into a new array and format it to match the gallery items array, here a code snippet of how it would look like:

let results = await wixData.query("collection").contains('referenceFieldKey', dynamicItem._id).find()
 let galleryItems =[]; //to store the imag items for the gallery
 let image ={};//to create the item in the gallery items format "src":"/image.."
 let keys = ['src']
    results.items.forEach((element)=>{
        let values = [element.imageSrcFieldKey]
        keys.forEach((key, i)=> image[key]=values[i]) 
        galleryItems.push(image)
        image ={};
    })

    $w("#gallery1").items = galleryItems;

I hope this helps

Massa