Hello respected members. I have two databases for my shop. One for listing products (productDatabase) the other for sellers (publisherDatabase).
I have created a “Premium” boolean field in the publisherDatabase. The Velo code first filters the publisherDatabase to get the _id of publishers with a premium plan. Then, it queries the productDatabase to get the products that reference the filtered publisher IDs. Finally, a repeater displays all products, I want the filtered items (those with references to premium plan sellers) and change the border color of the container (insider repeater) to blue.
My problem is that all items in a repeater have the same ID. So even though I finally filtered the items properly, the style change still applies to all containers. Ugh!!!
My page code:
// Query the "publisherDatabase" to get all the publishers
wixData.query("publisherDatabase")
.eq('premium', true) // Filter sellers with premium plan
.find()
.then(results => {
let publisherIds = results.items.map(item => item._id);
console.log("All publisher IDs:", publisherIds);
wixData.query("productDatabase")
.hasSome("reference", publisherIds)
.find()
.then(results => {
console.log("Filtered successfully");
// Change the border color of the container "#itemContainer" inside the repeater "#repeater" to blue if the "reference" field of the item matches one of the publisher IDs
$w("#repeater").onItemReady(($item, itemData, index) => {
let container = $item("#itemContainer");
container.style.borderColor = "blue";
console.log("Container style changed to blue successfully");
});
})
.catch(error => {
console.log(error);
});
})
.catch(error => {
console.log(error);
});
I played around with chatGPT and it told me to create indexes for the container. I applied its example but it did not work, it broke the style change.
ChatGPT suggestion:
$w("#repeater").onItemReady(($item, itemData, index) => {
let container = $item(`#itemContainer${index}`);
container.style.borderColor = "blue";
console.log("Container style changed to blue successfully");
I would be very grateful if someone could point me in the right direction.