Hey! I’m trying to display a list of 8 or less youtube videos that the api receives by searching up keywords from the text from a dynamic page. The api and the links are working great but I only want to display videos based on the number of items in the list (for ex: If only 2 videos show up, I only want to show 2 out of the 8 video players). I tried doing .hide and .show but I keep getting this error and I’m not sure what to do.
I’m new to wix and any help would be great!
Here’s my attempt so far:
import wixData from ‘wix-data’ ;
import { fetch } from ‘wix-fetch’ ;
import wixFetch from ‘wix-fetch’ ;
import { getVideos } from ‘backend/videoSearch.jsw’ ;
//import “public/videos.html”;
$w . onReady ( function () {
$w ( "#dynamicDataset" ). onReady (() => {
let name = $w ( "#dynamicDataset" ). getCurrentItem ();
$w ( '#title' ). text = name ;
let name1 = name.title ;
let videos = [];
let videoLinks = [];
$w ( "#videoPlayer1" ). hide ();
$w ( "#videoPlayer2" ). hide ();
$w ( "#videoPlayer3" ). hide ();
$w ( "#videoPlayer4" ). hide ();
$w ( "#videoPlayer5" ). hide ();
$w ( "#videoPlayer6" ). hide ();
$w ( "#videoPlayer7" ). hide ();
$w ( "#videoPlayer8" ). hide ();
getVideos(encodeURI ( name1 ))
. then ( response => {
if ( response.length ){
let x = response.length
**for** ( let i = 0 ; i < x ; i ++) {
videos . push ( response[i ]. id.videoId );
}
let z = videos.length
**for** ( let j = 0 ; j < z ; j ++) {
[videoLinks](videoLinks.push("https://www.youtube.) [.](videoLinks.push("https://www.youtube.) [push](videoLinks.push("https://www.youtube.) [(](videoLinks.push("https://www.youtube.) ["https://www.youtube.](videoLinks.push("https://www.youtube.) com/watch?v=" + videos[j ])
}
let a = videoLinks.length
**for** ( let k = 0 ; k < a ; k ++){
$w ( '#videoPlayer' + k ). src = videoLinks[k ]
$w ( '#videoPlayer' + k ). show ()
}
}
})
});
})