Image from data query only loads some of the time

Hi team,

I run database query in the page’s onReady (no dataset involved). I then add various fields from result 0 of the query to various elements on the page (not to a repeater). All the text elements load absolutely fine. But the image from the query only adds some of the time.

Presumably this is because the image is not yet ready when I add it. Is there some sort of onReady for images from the database?

So far I have tried to add a debounce timer to wait a bit and then load the image but it is still inconsistent.

Page here: https://www.planspace.co/eventsmap and simplified code below.

Any help would be much appreciated :slight_smile:

Similar post to this: https://www.wix.com/corvid/forum/community-discussion/data-is-not-ready-on-onready but have yet to find a solution.

function findEvents (){

mainQuery.and(tagQuery.and(dateQuery.and(searchQuery1.and(searchQuery2.and(searchQuery3.and(searchQuery4))))))
  .ascending('priority')
  .find()
  .then( (results) => {
      events = results.items;
})

//// a few other things in between, and then, with i = 0  ///

function loadDetails(i) {
 
    $w('#title3').text = events[i].title;
    $w('#text2').text = events[i].area;
    $w('#time3').text = events[i].run;
    $w('#location3').text = events[i].locationName;
    $w('#eventImage3').src = events[i].eventImage;
    $w('#eventImage3').tooltip = events[i].title;
    
    // all of this works fine apart from the event image src only sometimes works. 
    // Seems to be a live site only problem.
    
}

Fixed by putting image in repeater, pushing just result 0 into repeater data array and using the repeater itemReady to display image.