Well the logic is right, as long as there is another item keep deleting…Not sure about the syntax though.
What error do you get on the developer console?
export function cleanButtonOnClick(event, $w) {
let dataset = $w("#dynamicDataset"); // or the name of your dataset
dataset.onReady(async() => {
while (dataset.getCurrentItem()) {
await dataset.remove();
}
});
dataset.refresh();
}
function clear() {
//let user = wixUsers.currentUser;
//let userId = user.id;
// const itemId = event.context.itemId; // this is the item in the repeater assuming that the button is in the repeater.
wixData.query("yourdatabase") // get the item from the database collection.
.eq("userId")// if any specific field ("userId", userId)
.find()
.then((results) => {
removeItems(results.items);
console.log(removeItems);
});
}
async function removeItems(items) {
items.forEach(async (item, i) => {
await wixData.remove("yourdatabase", items[i]._id);
console.log(removeItems);
});
}