Hi
I have some downloadable books and maps that I want to show via images on the page.
it is a dynamic page and I have set up the link so it directs to user to the downloadable page but i want to keep a count. so every time it is click it register +1 click.
I have another page set up where all the books are on one via repeater and that records the clicks perfectly (thanks to help on this page).
Thanks in advance
Code is below
let clicktitle = $w( ‘#image26’ ).clickAction;
export function button29_click(event) {wixData.query( “StepbyStepGuides” ).eq( ‘title’ ,clicktitle).find().then((result) => {
let answersitem = result.items[ 0 ];
let id = answersitem._id;
answersitem.ebookDownloadCount++;
wixData.update( “StepbyStepGuides” ,answersitem).then(()=>{
$w( '#dataset1' ).refresh();
});
})
}
Code for the other working page using a button and repeater
import wixData from ‘wix-data’ ;
export function button29_click(event) {
const data = $w( “#repeater2” ).data; ///<- put here the repeater id insted of ‘repeater1’
let answersitem = data.find(item => item._id === event.context.itemId);
if (!answersitem.ebookDownloadCount) { // the default value is null , you need to check if null →
answersitem.ebookDownloadCount = 1 ;
} else {
answersitem.ebookDownloadCount++; // increment field by 1
}
wixData.update( "StepbyStepGuides" , answersitem).then(() => {
$w( "#dataset2" ).refresh();
});
}