I manage it like this,
let productId
let clickedItemData = $w("#datasetCompare").getCurrentItem();
if (clickedItemData !== null) {
const numberOfItems = $w('#datasetCompare').getTotalCount();
console.log(numberOfItems)
$w('#datasetCompare').getItems(0, numberOfItems).then(results => {
const items = results.items;
items.forEach(item => {
wixData.remove('Compare', item._id);
});
});
}
$w("#buttonAddCompare").onClick((event) => {
let $item = $w.at(event.context);
clickedItemData = $item("#datasetProduct").getCurrentItem();
productId = clickedItemData._id;
wixData.query("Compare")
.find()
.then((results) => {
let numberOfItems = results.totalCount;
console.log(numberOfItems);
if (numberOfItems === 3) {
$w('#compareErrorMes').show();
} else {
wixData.insert('Compare', clickedItemData)
}
})
if (itemObj.categoryTitle === 'projectors') {
$w('#compareBox').show();
}
});
The problem is if many users will enter at the same time, I think we should set a number for each user in the database. And the three products that he will add a compare database be a reference of number id of the same user.
what are you saying? How do you think it can be done?