Getting an error on a forEach repeater loop

I am trying to change the image in the repeater. It works for some items but not all and puts up an error.

export function repeater1_itemReady($item, itemData, index) {
    $w("#repeater1").forEachItem( ($w) => {
        wixData.query("AllTeams")
                .eq('title', itemData.team)
                .find()
                .then((results) => {
 let Item = results.items[0].twitter;
                    $item("#image7").src = Item;
                });
        });
    console.log(itemData)
    $w('#repeater1').show();
    $item("#text35").text =  itemData.team;
    $item("#text36").text =  itemData.franchise;
    $item("#text38").text =  itemData.wins + " - " + itemData.loss;
 //$item("#text36").text =  itemData.players[3].PlayerName;
 

 }

So what the page does is grabs data from an API and fills in the repeater with data from team stats. I am trying to get the image from my data to show in the repeater for the teams logo.
Here is the link to my site https://www.rscstreamtools.com/blank please pick the Amatuer tier as the others are not fully linked yet.

Any help would be great,
Thanks

So if I load on mobile all the logos load, but on Chrome on my Mac they do not (some but not all).

And also works on windows, so why not on mac???

Hi Shawn,

Personally, I try not to make so many calls to the server for data if I can avoid it. Do you get an error if you put in a condition: results.items.length > 0?

Try querying AllTeams once (without specifying the team) in the page onReady, so you have those results in memory prior to the itemReady loop running. Then in the itemReady function, loop through the AllTeams results array to find the appropriate image to display. I’m thinking that the query execution is getting hung up for some reason on Chrome for the Mac, and meanwhile the itemReady loop continues on.

Thanks Anthony, I have got the AllTeams in an array now with the logo location in the array. But I can’t figure out to write the loop through array to grab the logo location. I have been trying all morning and my head hurts, I am sure it’s just one small thing I’m doing wrong.

I’m noticing something else looking at the code is that you have a forEachItem loop within an itemReady function, which itself is a looping function. So, you won’t need both of these, but I don’t know enough about how you’re doing things in the dropdown code to suggest one way or another. In any event, this code will hopefully get you going:

import wixData from 'wix-data';
let AllTeams = [];
 
$w.onReady(async function () {
   let results = await wixData.query("AllTeams").find();
    AllTeams = results.items;
});

export function repeater1_itemReady($item, itemData, index) {
    AllTeams.forEach((rec) => {
       if (rec.title === itemData.team){
            $item("#image7").src = rec.twitter;
        }
    })
    $item("#text35").text =  itemData.team;
    $item("#text36").text =  itemData.franchise;
    $item("#text38").text =  itemData.wins + " - " + itemData.loss;
    $w('#repeater1').show();
 }

Thanks so much, works great!!

Thanks so much, works great!!!