Hello! Short overview, working on a site that has users submit events in their area, and then can find others by checking the calendar or map to find more events. Current issue is,
-
Using FullCallendar JS
-
Trying to take my database info found through my wixData.Query, and put it into my FullCallendar.
-
Specific issue I am having is returning any sort of data out of a wixData.query. I always get undefined or promise<>
-
Don’t need any help with getting it into fullcallendar or anything yet, Just need to figure out how to get information out of a wixData.query
function dateChanger () {
return wixData.query('UserinputShows')
.find({suppressAuth: true})
.then((results) => {
//Get a date from one of the items in the database
let date1 = results.items[0].date
//console.log(date1);
//convert it to the right type
let correctDate = date1.toISOString();
return correctDate;
})
}
console.log(dateChanger())
I’ve tried it a few other ways messing with async and await, but whatever I do I just cannot get any info out of the dateChanger function. Any Advice? I know it’s probably something easy but my lack of experience is taking over here.
EDIT: made even more simple, I just need to know how to return things from a wixData.query search so I can use them in other parts of code. If that isn’ t possible or I am extremely lost please point me in the right direction
EDIT 2: Or I can even get the item of info out and into this function call…
let newDate = $w.onReady(async function () {
const item = await dateChanger()
console.log(item);
})
And call it there, but even then, I still come to the same issue of only being able to log info and not use it.
EDIT 3
This time I am starting to understand more about async await but still unable to retrieve any information from them.
import wixData from 'wix-data';
var date1;
let array1 = []
async function dateChanger () {
const results = await wixData.query('UserinputShows')
.find({suppressAuth: true})
//Get a date from one of the items in the database
date1 = results.items[0].date
//convert it to the right type
let correctDate = date1.toISOString();
let dateArray = []
for(let i = 0; i < results.items.length; i++) {
dateArray.push(results.items[i].date)
}
return dateArray;
}
//The method below provides me with just the empty dates changed array and not the new array, why is this?
let datesChanged = []
dateChanger().then(resolvedValue => {
datesChanged = resolvedValue
})
console.log(datesChanged);