ANY HELP IS FANTASTIC (I LOVE YOU IF YOU ANSWER) (PROJECT IS DUE TOMORROW)
I have some code so that the visitor clicks on a button and an element is taken off an array i have. this is what i want the code to do. but once you refresh the page, the array goes back to the original.
how can i make so that when you click on the button the array is permanently affected?
should i be using something else?
like a dataset?
if so, how should i use that dataset?
how do i take elements off datasets permanently?
PLEASE
THANKYOU
Hi Chris!
Really fun idea!
I'd suggest you to put all the names in a collection (each name is an item).
Then, use a query from your page to retrieve all the items as an array.
Use your function to draw a name out of the array (show it to everyone) and then - delete it from the collection using the remove() function.
Then draw again!
It should be something like that:
import wixData from 'wix-data'; let familia; let rand; $w.onReady(function () { wixData.query("familia") .find() .then( (results) => { familia = results.items; } ); rand = Math.round(Math.random()*familia.length); } export function drawButton_click(event) { //Apply your logic. //Draw item and show your message. } export function use_click(event) { wixData.remove("familia", familia[rand].id) .then( () => { wixData.query("familia") .find() .then( (results) => { familia = results.items; rand = Math.round(Math.random()*familia.length); //+all your messages } ); } ) } export function dontUse_click(event) { rand = Math.round(Math.random()*familia.length) //+all your messages }
Let me know if it works for you and don't forget to adjust all the field names and field keys.
Doron.
Abyone else want to answer?
Wow! thank you! I'll get back to you soon
Hi Chris,
Can you explain what you mean by "the visitor clicks on a button and an element is taken off an array i have."?
In general yes, databases are the way to save data and keep it in store.
You can use datasets in order to save/retrieve/update data to the certain database it is connected to.
Here are some articles that will help you better understand those methods:
About Database Collections
About Connecting Page Elements to Database Content
Please also explain what you mean by "how do i take elements off datasets permanently"
and what are you trying to achieve so we'll be able to figure out the best solution for your case.
Doron.