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

90
Visualizações
Combining / Nesting Sequential API Requests In Javascript

I'm creating an asynchronous function as a method within a Vue instance, which I will invoke once the component has mounted.

What I need to do

After the resolution of a first API request (getDevicesInOrganization), I need to iterate over the array of results from this response, and make more API requests (getDeviceVariableData) using a value passed in as an argument from each result(from first requests response). Then push the value I get back from each response of each getDeviceVariableData API request to an array.

What I've tried

I create a single async function called (called getOfflineListData) that will house the other requests (and get invoked when the component is mounted). Inside getOfflineListData the getDevicesInOrganization request is invoked, and I try to make the additional requests by iterating over the response, but I get an array of undefined values.

    getOfflineListData: function () {
      this.getDevicesInOrganization().then((data) => {
        data.results.forEach((result) => {
          this.names = result.name
          this.ids = result.id

          this.deviceRequestPromises.push(
            this.getDeviceVariableData(result.label),
          )
        })
        Promise.all(this.deviceRequestPromises).then((data) => {
          console.log(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