Hello Guys,
I have a Online Shopping Website where I am displaying products from a Database in a Repeater.
In the Database, I have 2 or more currencies for the same product
'adultprice' contains the price in MUR
'adultEur' contains the price in EUR
The rates are to be updated manually every week.
On the page I have a Dropdown as below
Now whenever someone selects EUR from the dropdown I want the price from the EUR column in the database displayed inside the repeater in text element $w("#aprix").text
Same for USD, MUR, GBP and so on
I tried this code below but to no avail
export function dropdown1_change(event, $w) {
getCurrency();
}
function getCurrency() {
let exid = $w("#iid").text;
wixData.query("SalesInventory")
.eq("title", exid)
.find()
.then((results) => {
let items = results.items;
items.forEach((item) => {
if ($w("#dropdown1").value === 'EUR') {
item.adultEur = $w("#aprix").text;
} else if ($w("#dropdown1").value === 'MUR') {
item.adultPrice = $w("#aprix").text;
} else {
item.adultPrice = $w("#aprix").text;
}
});
});
}
Does anyone have any suggestion ?
Thank you
Hey
When you are about to change values inside a repeater you need to loop through the repeater. Read in the docs about this: https://www.wix.com/code/reference/$w.Repeater.html#forEachItem
So what you need to do is take the results.items or the items variable you have and set that items to the repeaters data. $w("#repeater-ID").data = items;
Then the data has been changed in the repeater and after that you need to loop through that data with the below code.
$w("#myRepeater").forEachItem( ($w, itemData, index) => {
// Do you if statements here and assign the elements their values
$w("#aprix").text = itemData.adultEur; // Set the EURO price field to the aprix field
} );