Hey everyone! I’m trying to implement a button and a text, which displays the total clicks on the button. This is my code so far:
import wixData from ‘wix-data’ ;
export function button1_click(event) {
wixData.query( “Klicks” ).find().then((result)=>{
let answersitem = result.items[ 0 ]; //item with values
let id = answersitem._id; // this will be used for
//writing data back
answersitem.result++; // increment field with yes by 1
// write updated value back to collection
wixData.update( “Klicks” , answersitem).then(()=>{
// refresh dataset to show new value
//(this should be done in promise,
//after updating collection)
$w( “#dataset1” ).refresh();
});
})
}
My Collection is called “Klicks”, the corresponding line in the database “totalKlicks”, the button “button1” and the text, which should display the total clicks: “result”.
I took this piece of code from another forum question but always recieve the answer “$w(…).refresh is not a function” when running.
Does anyone have an idea how to solve this?
Thanks already!