I have a collection with 3 fields, each with 1 image.
I want to link a gallery on a dynamic page to the collection images.
I've tried placing the code that Yoav gave as an example here.
My attempt is:
export function dynamicDataset_onReady() {
let item = $w('#dynamicDataset').getCurrentItem();
$w('#gallery1').items = [
{src: item.image1},
{src: item.image2},
{src: item.image3} ];
}
but nothing is happening in the preview page. There are no console messages.
I think perhaps I've neglected an import statement, or maybe I'm placing the code altogether in a different page.. right now it's on the 'page' tab of the code editor in the dynamic page.
Any help would be appreciated.Thank you.
Your dataset's onReady() function was never called. As an example, you can include it in the page onReady() function.
$w.onReady(function () { $w("#dynamicDataset").onReady(() => { console.log("The dataset is ready"); let item = $w('#dynamicDataset').getCurrentItem(); $w('#gallery1').items = [ { "src": item.images }, { "src": item.image2 }, { "src": item.image3 } ]; }); });
As you can see in the above code, the Field Key of the first image was incorrect - it needs to be images (not image1).
I tried this and it runs fine.
Good luck,
Yisrael