I have created a collection with 3 columns (id, minutes, updated). I want to get the values of minutes & updated. I get undefined for these two, whereas id is returned right. I use below code:
wixData . query ( “minutes_meditate” )
. find ()
. then ( ( results ) => {
let a = results . items [ 0 ]. Minutes
console . log ( a ); //works for Id, not for Minutes, Updated
} )
Why is this happening?
If you console.log() the results.items[0] you might find your answer. What does that show you?
It prints the info for 1st row of the collection correctly. console.log(results.items[0].Id) prints the id normally, but console.log(results.items[0].Minutes) prints undefined
Sorry perhaps I wasn’t clear. By console logging all the data in that item, you will see what the code is expecting.
For example in the screenshot below, my results.items[0] returns the entire object (red box 1), which then tells me what I need to write in my code.
If I want locationName in my case, I can console.log(results.items.[0].locationName) and the results of that are shown in red box 2 in the screenshot.
By logging results.items[0] the object will tell you what the code expects
Yes, that’s the problem. In your example, results.items.[0].locationName prints undefined in my case, while the collection has a value for locationName. And results.items[0] prints without error
Ok, I made it work. Thanks