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
Thanks for the help Yisrael! It works.
Can you access this?:
https://editor.wix.com/html/editor/web/renderer/edit/ba7ae0d4-f6da-4057-ac05-eee7e74b5f6f?metaSiteId=99cf63d4-5d5e-4f70-b6ce-d77f8a3b4302&editorSessionId=F33CA352-7FBA-4DD0-B00A-E38E70BCB7AE
Please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor.
Hi Yisrael,
The code I posted is the only code I have on the page.
Besides the gallery I have some other text boxes, background fills and a few buttons that link to documents.
I don't think it has anything to do with it..
Perhaps I am missing something from the code, like a top-level function..?
Hi Yafim,
Need more information in order to help. What components do you have on your page? What other code do you have?
Yisrael=