Hi,
Im having issues connecting my elements to a source using corvid.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
$w.onReady(async function () {
let user = wixUsers.currentUser;
if(user.loggedIn)
return loadWishlist();
$w('#wishlist').collapse();
$w('#emptyWishlist').expand();
});
async function loadWishlist(){
let user = wixUsers.currentUser;
let wishlistResult = await wixData.query("WishList")
.eq("userId", user.id)
.include("productName")
.find()
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 ProducsStore = wishlistItem.ProductsStore
ProducsStore.image = "image",
ProducsStore.name = "name",
ProducsStore.price = "price"
$w('#image').src = ProducsStore.image;
$w('#name').text = ProducsStore.name;
$w('#price').text = ProducsStore.price;
$w('#removeItem').onClick(removeItem(wishlistItem.name));
$w('#image').onClick(() => {
wixLocation.to(ProducsStore.productPageUrl);
}
);
}
function removeItem(name) {
return async function() {
await wixData.remove('WishList', name);
loadWishlist();
}
}
This is all I have on my page. so, what i need is:
I have 2 databases. 1 is ProducsStore where all the information about the products are located, and 2 is WishList. So on wishlist I have 2 columns 1 with the users’ id and the second with the product name (this is a reference type). so I am doing a query on wishlist to then get the information form the ProducsStore
but when I preview I get this code:
Wix code SDK error: The “onItemReady” function of “wishlist” threw the following error: Cannot set property ‘image’ of undefined
What am I doing wrong?