I have a calendar type database with various text and image fields and also two number fields MONTH and DAY which I use to create and display dated content in a kind of static calendar.
I would like to reckon the current date and then display one of my items based on the calendar month and day using my MONTH and DAY fields in my database.
For example, if it is February 14, I would like to display a repeater type element for all the entries that I have tagged with MONTH = 2 and DAY = 14.
Could use some pointers on how to retrieve the information and then pass it to an element.
Many thanks for any direction.
Thought I was making progress but failing on the first hurdle.
Right now the erroneous first entry in the database seems to be picked up (regardless of field matching for today's date via the numbered fields) and PARTIALLY populates my repeater element but this is not the database "row" of interest.
I set the properties for the repeater element to run LoadRepeater, OnReady.
I must be missing some fundamental concept here. I am not getting any runtime errors. Any pointers would be appreciated.
What is also disconcerting is that even though something is not working and I am not getting the properly filtered data for today's date, ONLY SOME OF my assignments for fields are being picked up regardless.
I would have expected if the wrong row was picked up (as it seems to be), I would still have the assignments correctly made for text36,41,38, etc ....) while only some of them are occurring.
======
import wixData from 'wix-data'; export function LoadRepeater(){ // get date object that you can obtain the current day and month from. let today = new Date(); let yearValue = today.getFullYear(); // getMonth() is 0 to 11 based, meaning 0 is January, 1 is Feb, etc. // So, you need to add a month presuming you are storing January as 1. let monthValue = today.getMonth() + 1; let dayValue = today.getDate(); // based on numeric collection fields called month and dayOfMonth
//*** is the parameter supposed to be the data collection name? wixData.query("GUINEAPIGOFTHEDAY") .eq("month",monthValue) .eq("dayOfMonth",dayValue) .find() .then((results) => { console.log(results); // assign query results to repeater $w('#repeater3').data = results.items; // now, assign repeater elements data. In this example the two // elements receiving data are txtContent1 and txtContent2 tied to // fields named event and startTime. $w('#repeater3').forEachItem( ($item, itemData, index) => { $item("#text36").text = itemData.title; $item("#text41").text = itemData.day; $item("#text38").text = itemData.callOut; $item("#text37").text = itemData.comment; $item("#image37").image = itemData.image; }) .catch( (err) => { let errorMsg = err; }); }) }
Thank you! I'll give it a try.
Deborah,
You could do this either using a dataset or a direct query. This example uses the latter approach. You could call the LoadRepeater function in the page onReady. Here is some documentation to help you better understand what's going on with the code:
https://www.w3schools.com/js/js_date_methods.asp
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html
https://www.wix.com/corvid/reference/$w.Repeater.html#forEachItem
https://www.wix.com/corvid/reference/$w.Repeater.html
export function LoadRepeater(){ // get date object that you can obtain the current day and month from. let today = new Date(); let yearValue = today.getFullYear(); // getMonth() is 0 to 11 based, meaning 0 is January, 1 is Feb, etc. // So, you need to add a month presuming you are storing January as 1. let monthValue = today.getMonth() + 1; let dayValue = today.getDate(); // based on numeric collection fields called month and dayOfMonth wixData.query("schedEvents") .eq("month",monthValue) .eq("dayOfMonth",dayValue) .find() .then((results) => { console.log(results); // assign query results to repeater $w('#repeater1').data = results.items; // now, assign repeater elements data. In this example the two // elements receiving data are txtContent1 and txtContent2 tied to // fields named event and startTime. $w('#repeater1').forEachItem( ($item, itemData, index) => { $item("#txtContent1").text = itemData.event; $item("#txtContent2").text = itemData.startTime; }) .catch( (err) => { let errorMsg = err; }); }) }