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
![](https://static.wixstatic.com/media/a27d24_ea2055001ac843248ca7451849c81090~mv2.png/v1/fill/w_423,h_322,al_c,q_85,enc_auto/a27d24_ea2055001ac843248ca7451849c81090~mv2.png)
'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
![](https://static.wixstatic.com/media/a27d24_c78240e5dc444713a1e5f058f9900575~mv2.png/v1/fill/w_980,h_583,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/a27d24_c78240e5dc444713a1e5f058f9900575~mv2.png)
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
} );
Glad it helped
Thanks again Andreas!
The let item = results.items; was missing a [0]
Hey Andreas,
How are you today ?
I tried it but the repeater elements are just getting a value of 'undefined'
export function dropdown1_change(event) { let exid = $w("#iid").text; $w("#repeater1").forEachItem( ($w) => { wixData.query("SalesInventory") .eq('title', exid) .find() .then((results) => { let item = results.items; $w("#repeater-ID").data = item; getCurrency(item); }); }); } function getCurrency(item) { $w("#repeater1").forEachItem(($w, itemData, index) => { if ($w("#dropdown1").value === 'EUR') { $w("#aprix").text = String(item.adultEur); } else if ($w("#dropdown1").value === 'MUR') { $w("#aprix").text = String(item.adultPrice); } else { $w("#aprix").text = String(item.adultPrice); } }); }
Can you point out my errors ?