Hello,
I wrote the code below to merge data from a MenuItems collection (20 rows) with a Wishlist collection (3 rows). The output below that is exactly what I anticipated - you can see that it returns 20 items with 3 labeled as being on the wishlist. Now I need to figure out how to get that output into a repeater.
How can I get the data in the process into the proper format to be loaded into a repeater?
Thank you very much for any thoughts, ideas, and/or suggestions!
Jason
CODE:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
// OnLoad Get Menu Items for this User ------------------------------------------
$w.onReady(function () {
loadMenuItemsforUser();
});
// Load Menu Items for this User by Combining MenuItems with Wishlist -----------
async function loadMenuItemsforUser(){
// Retrieve Current User's ID -----------------------------------------------
let user = wixUsers.currentUser;
// Query Menu Items Collection ----------------------------------------------
var MenuItemsArray_ID = [];
var MenuItemsArray_Title = [];
var MenuItemsCount = 0;
await wixData.query('MenuItems').find().then((results) => {
results.items.forEach((item) => {
let myID = item._id;
let myTitle = item.title
MenuItemsArray_ID.push(myID)
MenuItemsArray_Title.push(myTitle)
MenuItemsCount = MenuItemsCount + 1;
})
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
// Query Wishlist Collection ------------------------------------------------
var WishlistArray_MenuItem = [];
var WishlistCount = 0;
await wixData.query('Wishlist')
.eq("userId", user.id) // Filter for Current User
.find()
.then((results) => {
results.items.forEach((item) => {
let myMenuItemID = item.menuItem;
WishlistArray_MenuItem.push(myMenuItemID)
WishlistCount = WishlistCount + 1;
})
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
// **************** NEED TO GET THIS DATA INTO A REPEATER ********************
// Combine MenuItems with Wishlist -------------------------------------------
for (var i=0; i<MenuItemsCount; i++) {
var ComparisonResult = "";
for (var j=0; j<WishlistCount; j++) {
if (MenuItemsArray_ID[i] == WishlistArray_MenuItem[j]) {
ComparisonResult = "is in Wishlist *********** ";
}
}
console.log(i, ":", MenuItemsArray_Title[i], ComparisonResult);
}
}
OUTPUT
0 : Peach BBQ Pork
1 : Seafood Splendora
2 : Peach Pie is in Wishlist ***********
3 : Peach Cobbler is in Wishlist ***********
4 : Peach Pancakes
5 : Peach Waffle
6 : Peach Spinach Salad
7 : Peach Stacker
8 : Blueberry Buckle
9 : Blueberry Pie is in Wishlist ***********
10 : Blueberry Pancakes
11 : Blueberry Waffle
12 : Blueberry Spinach Salad
13 : Blueberry Stacker
14 : Strawberry BBQ Pork
15 : Strawberry Shortcake
16 : Strawberry Crunch French Toast
17 : Strawberry Waffle
18 : Strawberry Spinach Salad
19 : Strawberry Stacker