I have a Wishlist collection and a Wishlist page using a repeater.
I need to be able to remove an item from the repeater when the user clicks a black X. This black X is assigned an async function in the myItemReady function and it seems to be working just fine.
However, when a user clicks the black X, I get the error: Operation (remove) not allowed on read-only dataset. The collection has Member-Generated Content, which works from other pages.
Can anyone help me figure out what’s going wrong?
Thanks, Jason
CODE:
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(function () {
loadWishlist();
});
async function loadWishlist(){
console.log("--------- Load Wishlist");
// Retrieve Current User's Wishlist Items
let user = wixUsers.currentUser;
let wishlistResult = await wixData.query("Wishlist")
.eq("userId", user.id)
.include('menuItem')
.find()
// Determine if there are Any Items in their Wishlist
if (wishlistResult.length > 0) {
$w("#wishlist").expand();
$w("#emptyWishlist").collapse();
$w("#wishlist").data = wishlistResult.items;
$w('#wishlist').onItemReady(myItemReady);
}
else {
$w("#wishlist").collapse();
$w("#emptyWishlist").expand();
}
}
function myItemReady($w, wishlistItem){
let menuItem = wishlistItem.menuItem;
$w('#image').src = menuItem.photo;
$w('#title').text = menuItem.title;
$w('#month').text = menuItem.month;
$w('#removeItem').onClick(removeItem(menuItem._id)); // Seems to work OK here
}
function removeItem(id) {
return async function() {
console.log("--------- Removing Item with ID:", id) // Seems to work OK here
let currentItem = $w("#dataset1").getCurrentItem();
$w('#dataset1').remove(); // ERROR MESSAGE: Operation (remove) not allowed on read-only dataset
loadWishlist();
}
}