Liking System

Hello , good morning , I am trying to implement this code, but it doesn’t work, can anybody help me? thank you

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( function () {

$w(“#dynamicDataset”).onReady( () => {

let currentNumber = $w(“#dynamicDataset”).getCurrentItem();
let likes = currentNumber.likes;
if ( likes === null ) {
$w(“#numberOfLikes”).text = 0 total likes.
} else {
$w(“#numberOfLikes”).text = ${likes} total likes.
}

$w(“#iconButton1”).onClick( (event) => {
let getCurrentNumber = $w(“#dynamicDataset”).getCurrentItem();
let newNumber = Number(Number(getCurrentNumber.likes) + 1)
$w(“#dynamicDataset”).setFieldValue(“likes”, newNumber)
$w(“#dynamicDataset”).save()
.then( (item) => {
let fieldValue = item.likes;
$w(“#numberOfLikes”).text = ${fieldValue} total like(s).
$w(“#dynamicDataset”).refresh();
} )
. catch ( (err) => {
let errMsg = err;
} );
} )
} );
});

what are the EXACT problems you’re having?

Hello Heath, thank you for your reply, now the like system wix code is working, but the deep problem is you must click twice before start counting. Because the code is created to have the 0 value by defect, but items are added by clients so the item are added in the database with no value in the like (number field), hope you understand my meaning, thank you

You can do it like in this previous forum post below.
https://www.wix.com/corvid/forum/community-discussion/liking-posts-in-repeater-comprehensive

Thank you givemeawhisky, thanks a lot