Need help with fetch and Repeater

Summery :
Hey I want help with this…
I’m getting a json from api using fetch
and then I’m using the json array in repeater, now when the page fully loaded wix call the api and assign the values!

The problem is :
Repeater items holders appear with the dummy data and after 2 seconds wix assign api data.

Code :
getProducts is a function in the back-end where i call the api with token, and this function return a json array.


getProducts().then(items => {

   $w("#repeater1").onItemReady(($item, itemData, index) => {

       $item("#image1").src = itemData.image;
       $item("#text10").text = itemData.name;
       $item("#text8").text = itemData.Description;
       $item("#text6").text = itemData.price.toString();
       $item("#button2").link = itemData.url;

   } // end onItemReady
); // end getProducts function

// assign the json array to data repeater 
$w("#repeater1").data = items;

});

The Question is there is a way to assign the values along as the page loading ?

2 thinks you can do:

  1. start the download while the page is loading (outside $w.onReady)
  2. hide the repeater until data is ready
let promise = getProducts();
$w.onReady(() => {
promise.then(items => {
    $w("#repeater1").data=items;
    $w("#repeater1").show();
});

$w("#repeater1").onItemReady(($item, itemData, index) => {
       $item("#image1").src = itemData.image;
       .....
    })

was such a same the situation and I have, made all as you said and me, too, very helped

Thanks this is really way too fast and worked :heart:. just you forgot to close the braces at the end last line should be replaced by })}) .

@plomteuxquentin Hey, I have parameters passed to the function like order id is there is a way to assign them and call the API as the page loading

yes there is, you can use that API for filtering your request https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#eq