Count and display button clicks

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!

https://russian-dima.wixsite.com/meinewebsite/blank-26

Thank You, but I need a counter which counts all clicks globally :slight_smile:

@info80859

import wixLocation from 'wix-location';
 
var clickCounter //<--- global variable??? isn't it?
 
$w.onReady(function () {
    clickCounter = 0
});
 
export function button1_click(event) {
    clickCounter=clickCounter+1
 
    if (clickCounter>0) {$w('#vector1').show()}
    if (clickCounter>1) {$w('#vector2').show()}
    if (clickCounter>2) {$w('#vector3').show()}
    if (clickCounter>3) {hide_allSTARS(), wixLocation.to("https://www.google.de")}
    $w("#TXT").text = clickCounter.toString()
}
 
function hide_allSTARS (parameter) {$w('#vector1').hide()}

What exactly do you mean, when you say…

I need a counter which counts all clicks globally :slight_smile:
There could be a lot of interpretations for this sentence.

Perhaps you use the search of this forum, i am sure you will find a lot of other posts, related to the given topic…