I need to assign values from the collection colPageTypes to some variables, depending of the value of the ‘position’ field of the collection. I have tried with this code without success. I know that the problem is caused because I use the index [0] or [1] and this avoid the posibility of find the records with position 1 or 2 in ALL the collection, but I don’t know how to retrieve these calues without this index! I only show the code for position 1 and 2 but really I have to do it with 20 positions.
$w.onReady( function ()
{
let PageTypeActual = “A1”
let productCode01= null
let price01= null
let wrasMessage01= null
let productCode02= null
let price02= null
let wrasMessage02= null
wixData.query('colPageTypes')
.eq("pageType",PageTypeActual)
.find()
.then ( (results) =>
{
**let** items = results.items;
**if** (items[0].position === 1)
{
productCode01=items[0].productCode;
price01=items[0].price;
wrasMessage01=items[0].wrasMessage;
}
**if** (items[0].position === 2)
{
productCode01=items[1].productCode;
price01=items[1].price;
wrasMessage01=items[1].wrasMessage;
}
});