Hello I ask for help for this thing, I need to show the result of a query in a particular field I tried looking at this code.
The search is done by an input field called #inputTest which looks for the result in my table the corresponding entry in the ‘code’ column. I want to show the corresponding field in the same row of the table found on the column called ‘redirect’
export function buttonTest_click() {
wixData.query(‘RedirectCerimonie’)
.eq(‘code’, $w(‘#inputTest’).value)
.find()
.then(res => {
let items = results.items;
console.log(items);
let item = items[7];
let redirect = item.redirect;
console.log(redirect);
});
}
Thanks for your help, no what I try to return and the 7 column of the row found with the query, which indicates the ‘redirect’ field of my table. I do not know how to give that result
I had a feeling that that’s what you were trying to do.
Fields (columns) aren’t accessed by index number. Just think what would happen if you made changes to the collection and the order of the columns changed. Pow! Bam! Things would break.
What you want to do is use the name of the column to get the desired field. So, if the column that you want is called thingie, then you would write:
let field = item.thingie;
Here’s what your code currently does:
This line in your code retrieves the items that were returned by the query:
let items = results.items;
This line in your code gets the 7th item (row) that was returned by the query:
let item = items[7];
And this line gets the column (field) called redirect:
let redirect = item.redirect;
Now, what results do you expect to get from the query?
Thanks I understood many things now, so not having 7 lines of a specific search the result will be undefine.
So I corrected the code like this:
export function buttonTest_click() {
wixData.query(‘RedirectCerimonie’)
.eq(‘code’, $w(‘#inputTest’).value)
.find()
.then(res => {
let items = results.items;
let item = items[0];
let redirect = item.redirect;
console.log(redirect);
});
}
So I look in the first line found that it should be the only column called ‘redirect’, and then check the result with the console.log
But I do not get the result because I have this error that I do not understand why there is: “results is undefine”