Retrieving a single value from a database with Code

Hi everyone

Sorry for asking an apparently stupid question - I still have to learn more about JavaScript. I have a collection called “Pages” with several fields (an attempt to create something like a multilingual CMS) and I’d like to dynamically display texts on a web site using the following code (normally, I use datasets, but in this particular case, I have to use code):

wixData.query(‘Pages’)
contains
.eq(‘context’, ‘Services’ )
.eq(‘language’, ‘ENG’ )
.find() // Run the query
.then(res => {
$w(‘#txtText’).text = res.items(‘para1’)
// Here, I do not know how to display the content of a field. My code does not give any error, but it does not work.
});

Can anyone tell me how to access a single field in the result of the query (there is exactly one record matching)?

Kind regards,

Chris

Hi Chris!

Can you please share a link to your site?
One of our WixCode Team will inspect it and provide you with a solution.

Doron.

Hi Doron, thanks a lot for your availability! The site that is concerned is www.agilis.services. However, we will be having several other sites, so we try to do something more or less generic. As we did not yet have a solution, the code is currently not online, but it is intended for the mobile pages which are currently duplicated for each language (the purpose would be to retrieve the strings from the table “Pages” rather than hard-copying them.

Hi again Chris!

There are other options!
Take a look at this tutorial article about code-less multilingual sites.

About your bit of code,
It seems like you either forgot to complete the ‘contains( )’ statement or just added it by mistake.
Take a look at the API of this method .
That might be the mistake that is breaking your code.

Hope it helps.

Doron. :slight_smile: