In order to create a dynamic slideshow on Editor x i followed these steps:
-
I added a progallery and named it ‘#dynamicSlideshow’
-
Added a text1 and named it ‘#slideTitle0’
-
Added a text2 and named it ‘#slideDescription0’
-
I created a database named ‘DynamicSlides’ with 3 fields ‘Title’(text),‘SlideBackground’(image) and ‘description’(text)
-
I added the following code in dev mode:
-
import wixData from ‘wix-data’ ;
$w . onReady ( async function () {
let slidesData = await getSlideshowDataFromDatabase ();
loadSlideshowData ( slidesData );
});
function loadSlideshowData ( slidesData ) {
const slideElements = $w ( “#dynamicSlideshow” ). slides ;
slideElements . forEach (( slide , index ) => {
$w ( # ${ slide . id }
). background . src = slidesData [ index ]. slideBackground ;
$w ( #slideTitle ${ index }
). text = slidesData [ index ]. title ;
$w ( #slideDescription ${ index }
). text = slidesData [ index ]. description ;
$w ( #slideButton ${ index }
). link = slidesData [ index ]. buttonUrl ;
})
}
function getSlideshowDataFromDatabase () {
return wixData . query ( “DynamicSlides” ). find (). then ( results => {
return results . items ;
})
}
I got back type error ‘Cannot read property ‘forEach’ of undefined’ can someone help me to solve this? Many thanks