Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
Multiple sequential async function calls in <script> that must be awaited, but await doesnt work

So I am trying to load several instances of a lottie animation and the JSONS are on a cdn, the problem is that loading these JSONS is async, and I have to do all of that in tags.

<script>
  // the list of urls
  const urls = ["url", "url", "url", ...]

  // the function that gets each of the jsons, creates an array and returns it
  const getLottieJSONs = (urls) => {
    const lottieJSONs = [];
                  
    for (let i = 0; i < urls.length; i++) {
      $.getJSON(urls[i], (data) => lottieJSONs.push(data))
    }

    return lottieJSONs;
  }

  // creating the instances of the lotties with the retrieved data
  const createLottieInstances = (lottieContainers, lottieJSONs) => {
    const lottieInstances = [];
   
    for (let i = 0; i < lottieContainers.length; i++) {
      lottieInstances.push(bodymovin.loadAnimation({
          container: lottieContainers[i], 
          renderer: "svg", 
          animationData: lottieJSONs[i],
        })
      );
    }

    return lottieInstances;
  }

  const lottieContainers = document.querySelectorAll(".ingredients-lottie-container");
  
  // this does not have the data, before moving on to creating the instances and so it gives empty array to createLottieInstances
  const lottieJSONs = getLottieJSONs(urls); 
  const lottieInstances = createLottieInstances(lottieContainers, lottieJSONs);

  // ... other code that uses the lottie instances ...
</script>

My end goal is to have all instances loaded before I get to the code that is using them with the actual json data.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda