Error in "Wishlist"(currentIndexChanged event)

Hi
I have followed the “wishlist” code from Code Queen Nayeli, as presented here;
https://www.totallycodable.com/forum/codes-for-templates/wish-list-add-to-favorites
I have followed the code strict, but, for me, something strange happens.
In page corresponding to “MyWishlist”, I can sometimes see a glimpse of the added items, but mostly they are not added to the repeater. The items are added to the database, but not added/visible in the repeater.
In the console log, I can see “onReady callback registered”, and “currentIndexChanged event”.
Guess the error (and the solution) is connected to this…
In my search for enlightening, I found this forum-thread:
https://www.wix.com/corvid/forum/community-discussion/filter-database-error-an-error-occurred-in-one-of-currentindexchanged-callbacks
My error seems quite the same, but not the solution…
I do not have the knowledge to figure out what is going on - on another test-site, it used to work.
I have triple-checked the permissions, datasets etc.

Can someone clarify me on this?
Thank you SO MUCH for your help in advance:-)

For reference, I add the code and a link to my site page:
https://editor.wix.com/html/editor/web/renderer/edit/f0ed6faa-2879-4792-a595-893dcbe154d4?metaSiteId=fb1b61f0-deb1-4783-85a3-85b04b19bea6&editorSessionId=0b963381-5383-5ce7-9af1-c273fea404ff

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;

$w.onReady( function () {
getfilters();
});
function getfilters() {
let user = wixUsers.currentUser;
let userId = user.id;
console.log(userId);
wixData.query(“mittarbeid”)
.eq(“userId”, userId)
.find()
.then((results) => {
let items = results.items;
let firstItem = items[0];
var prod = ;
var i = 0;
console.log(results.length);
var vf = results.length;

         $w("#text36").text = userId; 

while (i < vf) {
console.log(i);
prod[i] = items[i].productId;
console.log(items[i].productId);
i = i + 1;
console.log(prod[i]);
}
console.log(prod);
$w(“#dsAndelsarbeid”).setFilter(wixData.filter()
.hasSome(“name”, prod)
);
});

Just so you know that Wix already have their own wishlist tutorial which you can open up in an editor and see how the elements are fully laid out on the page and to view all the code all written for it already.
https://www.wix.com/corvid/example/wishlist

As for following code, you seem to have entered a few extra lines on yours.

$w("#text36").text = userId; 

I haven’t watched the video, so is that meant to be in there as it isn’t listed on the page code.

The code for the Wish List page where you display the Members saved items:

import wixUsers from 'wix-users';
import wixData from 'wix-data';

$w.onReady(function () {
	getfilters();

});

function getfilters() {
	let user = wixUsers.currentUser;
	let userId = user.id;
	console.log(userId);
	wixData.query("wishlist")
		.eq("userId", userId)
		.find()
		.then((results) => {
			let items = results.items;
			let firstItem = items[0];
			var prod = [];
			var i = 0;
			console.log(results.length);
			var vf = results.length;
			while (i < vf) {
				console.log(i);
				prod[i] = items[i].productId;
				console.log(items[i].productId);
				i = i + 1;
				console.log(prod[i]);
			}
			console.log(prod);
			$w("#favorites").setFilter(wixData.filter()
				.hasSome("name", prod)
			);
		});
}


Also make sure that this page code for your dynamic item page is correct too.

The code for the Dynamic Item Page where you have the ‘Add to Wish List’ button:

import wixUsers from 'wix-users';
import wixData from 'wix-data';
let user;
var userID;
let itemObj;
var product_name;

$w.onReady(function () {
	$w("#Itemdetails").onReady(() => {
		product_name = $w("#text31").text;
	});

	user = wixUsers.currentUser;
	userID = user.id;
	let isLoggedIn = user.loggedIn;
	if (isLoggedIn === true) {
		$w("#Itemdetails").onReady(() => {
			testwish(product_name);
		});

	} else {
		wixUsers.promptLogin();
	}
});

function testwish() {
	let userId = user.id;
	wixData.query("wishlist")
		.eq("productId", product_name)
		.eq("userId", userId)
		.find()
		.then((results) => {
			let count = results.totalCount;
			if (count === 0) {
				$w("#addtowishlist").label = "ADD TO WISH LIST";
 			} else {
				$w("#addtowishlist").label = "REMOVE FROM WISH LIST";
			}
		});
}

function dothewish() {
	let userId = user.id;
	wixData.query("wishlist")
		.eq("productId", product_name)
		.eq("userId", userId)
		.find()
		.then((results) => {
			let items = results.items;
			let firstItem = items[0];
			let count = results.totalCount;
			if (count === 0) {
				let toSave = {
					"productId": product_name,
					"userId": userId
				};
				wixData.save("wishlist", toSave);
				$w("#addtowishlist").label = "REMOVE FROM WISH LIST";
			} else {
				wixData.remove("wishlist", firstItem._id);
				$w("#addtowishlist").label = "ADD TO WISH LIST";
			}
		});
}

export function addtowishlist_onclick() {
	dothewish(product_name);
}

Thank you so much for your quick reply!! Amazing!
I have played with the corvid/wix wishlist in the editor today, but since the wix wishlist use wix store, I still have problems.
I kind of have to mix this code-examples, but reference field gives me headache!

  1. The items collection(named “Andelsarbeid”) and items page (named “Andelsarbeid”) works fine
  2. The dynamic page Item(ID)(named “Andelsarbeid(ID)”) use the my-wishlist collection (named “mittarbeid2”) is the problem
    I am able to populate the data, but not able to save to the “mittarbeid2” datacollection, because I am struggling with the reference field. In the field, I am supposed to add the product _id from the items collection - but how??

This is a code snippet from the item page
This code is in testeng mode - I know it is wrong - but just can´t figure out how to add the referenced field _id into the "mittarbeid2"collection

function dothewish() {
let userId = user.id;
wixData.query(“mittarbeid2”)
.eq(“product”, product_name)
.include(‘product’) → using include???
.eq(“userId”, userId)
.find()
.then((results) => {
let items = results.items;
let firstItem = items[0];
let firstRefProp = firstItem.product._id–> just testing…
let count = results.totalCount;
if (count === 0) {
let toSave = {
“product”: firstRefProp–> here, the _id of the referenced collection should be
“userId”: userId
};
wixData.save(“mittarbeid2”, toSave);
$w(“#addtowishlist”).label = “REMOVE FROM WISH LIST”;
} else {
wixData.remove(“mittarbeid2”, firstItem._id);
$w(“#addtowishlist”).label = “ADD TO WISH LIST”;
}

    }) 
    . **catch** ( (error) => { 

let errorMsg = error.message;
let code = error.code;
} );

}