Async in page's OnReady

Can someone tell me why I keep getting inconsistent results in my repeaters? Here is the code:

$w . onReady ( async function () {
//$w(“#fleetRates”).onReady( () => {
let luxResults = await wixData . query ( “FleetRates” )
. gt ( ‘length’ , 40 )
. limit ( 3 )
. find ()
$w ( “#luxRepeater” ). data = luxResults . items ;

//});

//$w(“#fleetRates”).onReady( () => {
let chartResults = await wixData . query ( “FleetRates” )
. lt ( ‘length’ , 40 )
. limit ( 12 )
. find ()
$w ( “#chartRepeater” ). data = chartResults . items ;

});

Note: i’ve commented out the dataset onReady’s, this is a remnant of many attempts to streamline the loading of the repeaters. The problem is occurring on the live site, occasionally when I refresh the screen or have visited the site a bunch, the repeater is not retrieving the correct number of items. Of the buttons within the repeater are not working on the live site but work on the Preview. The inconsistencies are maddening.

Thanks in advance!!!

It’s a little difficult to determine what “inconsistent results” means since I really have no clue what kind of results you want. Some observations about your code:

  • Are you using a dataset to populate the Repeater? Since you are also populating the Repeater with code, you should disconnect the dataset from the Repeater.

  • If you want to populate the Repeater using code, then you will need an onItemReady() function to render the Repeater items.

  • In your code, you have two queries, with the second query overwriting the results in the Repeater of the first query.

What exactly are you trying to do? What do you want displayed in the Repeater?

Thanks for the reply and sorry for being vague. I think I found what was driving me crazy and my path back to sanity.

I was trying to use code to query and filter two repeaters on a page. I was also using the editor UI to link fields inside the repeaters back to the database. I didn’t assign the fields inside my code only jamming the whole query data back into the repeater:

$w ( " #luxRepeater " ). data = luxResults . items ;

I don’t know how Wix works but I’m betting the repeater was all confused …“do I listen to my editor wix code to go get the data? or do I listen to the dumb programmer trying to write a dataquery in the page code?”

My solution: nix the page code and just create another dataset, using the filters built into the editor!

I hope my mistakes will help others.