Hiding element if they are not in a database.

Hi everyone!

I have been trying to succesfully hide and show elements depedning on whether or not they have a source in a database.

In thsi case, I would like that a button “button36” 37, 38, 39 hides if there is no link to support it “adLink” in a database/set.

I share with you my code so far.

  $w("#dataset10").onReady(()=>{
		if($w("#dataset10").getCurrentItem().adLink){
			$w("#button36").show();
		}
	});
$w("#dataset11").onReady(()=>{
		if($w("#dataset11").getCurrentItem().adLink){
			$w("#button39").show();
		}
	});
	
 $w("#dataset12").onReady(()=>{
		if($w("#dataset12").getCurrentItem().adLink){
			$w("#button37").show();
		}
	});
	 $w("#dataset13").onReady(()=>{
		if($w("#dataset13").getCurrentItem().adLink){
			$w("#button38").show();
		}
	});

I appreciate any help I could get,

Thanks in advance!

What do you get if you console.log the below

let objItem = $w(" #dataset10 ").getCurrentItem();

Just from a quick observation, you only have show() and you don’t have hide() anywhere.

HI Yisrael and Andreas,

Thanks for your observations!

I found out there was another problem, the datasets where taking some time to load, and hence I tried a different approach described in the code below.

I leave my working code here if anyone may neeed to apply to to their own scenario.

setTimeout(() => {
if ($w("#button36").label.length ===0) {
		$w("#button36").collapse();
		} else {
			$w("#button36").expand();
			}
			
if ($w("#button39").label.length ===0) {
		$w("#button39").collapse();
		} else {
			$w("#button39").expand();
			}
			
if ($w("#button37").label.length ===0) {
		$w("#button37").collapse();
		} else {
			$w("#button37").expand();
			}
			
if ($w("#button38").label.length ===0) {
		$w("#button38").collapse();
		} else {
			$w("#button38").expand();
			}
			
			
			console.log($w("#button36").label.length >0);
			console.log($w("#button39").label.length >0);
			console.log($w("#button37").label.length >0);
			console.log($w("#button38").label.length >0);
			}, 4000);

Thanks for everything!