Auto hide gallery image from database

Hi, I’ve create an database with include 4 image on 1 row.
I would like to create a gallery which can hide the items if image of the database are null.

But seems it doesn’t work.

The log are:
The src parameter of item at index 2 that is passed to the items method cannot be set to null or undefined.

Here are my code:
$w.onReady( function () {
//TODO: write your page related code here…

let image1 = $w(“#dynamicDataset”).getCurrentItem().img;
let image2 = $w(“#dynamicDataset”).getCurrentItem().img2;
let image3 = $w(“#dynamicDataset”).getCurrentItem().img3;
let image4 = $w(“#dynamicDataset”).getCurrentItem().img4;
let image5 = $w(“#dynamicDataset”).getCurrentItem().img5;

if (($w(“#dynamicDataset”).getCurrentItem().img2) === null ) {
$w(“#gallery1”).items[2].hide();
$w(“#gallery1”).items[3].hide();
$w(“#gallery1”).items[4].hide();

}  **else if**  (($w("#dynamicDataset").getCurrentItem().img3) ===  **null** ) { 
    $w("#gallery1").items[3].hide(); 
    $w("#gallery1").items[4].hide(); 

}  **else if**  (($w("#dynamicDataset").getCurrentItem().img4) ===  **null** ) {   
    $w("#gallery1").items[4].hide(); 

} 

$w("#gallery1").items = [ { src: image1, }, { src: image2, }, { src: image3, }, { src: image4, } ];

Hi,
I’m truly sorry for the delay. Can you please send us the site URL so that I can have a look?

Thanks,
Tal.

Hi Tal,

Here is the URL, please take a look =]
https://www.csdiamond.hk/Products/4

Thanks,
Terry