Format an element based on value in dataset

Hi,

This is driving me crazy! I simply want to format #boxName depending on a particular value in my dataset. Eg. If ‘approved’ = 1 then style the box white, else style it blue but it is always returning “not approved” (in the console log) and therefore is skipping my if statement presumably because it is only looking at the first row in my dataset?

How do check all rows?!

wixData.query("MembersOnly")
        .find()
        .then((results) => {

        let valueApproved = results.items[0].approved;
        console.log(valueApproved);

         $w("#rptMembers").show();

         if (valueApproved === "1") {
            $w("#boxName").style.backgroundColor = "#FFFFFF";
            console.log("approved");
         } else {
            $w("#boxName").style.backgroundColor = "#7FCCF7";
            console.log("not approved");
                }
        })
}

Thanks,
Rachel

You have results.items[0].approved so you are specifying record 1 only

Thank you… how would I check all records?

@rachelskuse

let records = results.items;
records.forEach((record) => {
// Inside here you can reach each record by below syntax
valueApproved = record.approved;
});

@hello44
Many thanks, Andreas!

I actually go it working using the following…

$w("#datasetMembersOnly").onReady(() => {
     $w("#rptMembers").forEachItem(($w, itemData, index) => {
        if (itemData.approved === "1") {
                $w("#boxName").style.backgroundColor = "#FFFFFF"
         } else {
                $w("#boxName").style.backgroundColor = "#7FCCF7";
         }

     });
});