Wix Dataset

Hi everyone,
The website I am building consist of a coding problem .
I am creating a query of dataset from dropdown value and then send the result to the text.
But, the code is not working.
Here is my code -

export function dropdown1_change_1(event) { 
  wixData.query("Contact") 
  .contains("email", $w('#dropdown1').value) 
  .find()
  .then( (results) => {
 if(results.items.length > 0) {
 let firstItem = results.items[0]; 
   $w('#text7').text = firstItem;
   $w('#button6').show();
 
    console.log("text");
 
  } 
 
 
   });
}

But the text is stilll showing –

Thank You,
Ajit

Hello Ajit,

take a look at the RESULTS which you get.
Do a console.log …

console.log(firstItem)

What do you get to see in the console?
It is surely not what you are searching for, right?

You are searching for an eMail in your DATABASE chosen by the DROPDOWN right?

But you are getting an OBJECT, so it can not work.
You have to tell the CODE what you want to see especially of the founded OBJECT.

The OBJECT will contain everything which was founded in the column → “email”. But you need just some special values of it, right?

For example the TITLE…

console.log(firstItem.title)

Something like this.

Hi Ajit :raised_hand_with_fingers_splayed:

You’re assigning the text element an object as its value, text elements only accepts strings as their text values.

If you want to display an object as a text, you need to use the JavaScript JSON.stringify() function before assigning the object to the text property.

$w('#text7').text = JSON.stringify(firstItem);

Hope this helps~!
Ahmad

Ok, also a very useful information for me :sweat_smile:

Me too. Might come in handy! :slight_smile:

Glad that it was useful.