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

214
Visualizações
Leverage promise.all() to return default data used throughout site. Data not available when called

I have to make several calls to an API to get default data used throughout the site (the data is independent of each other, no key constraints). I am attempting to create a function that returns an object with all the returned data from the various calls. The API leverages a Django Restframework.

I was looking for data to be in this format:

defaultValues ={
   sysLvlList: {},
   phaseList: {},
   programList:{}
   missionList:{}
        }

Then be able to access the data through dot notation, defaultValues.sysLvlList etc. What I ended up doing was:

let defaultValues = {};
async function getSystemLevel_phase(){
    const sysLvl = get("/api/SystemLevelList_url/").then(r=>defaultValues.sysLvlList = r).catch(err=>showErrorAlert(err));
    const phase = get("/api/mmSelectorPhase_url/").then(r=>defaultValues.phaseList = r).catch(err=>showErrorAlert(err));
    const program = get("/api/ProgramList_url/").then(r=>defaultValues.programList = r).catch(err=>showErrorAlert(err));
    const mission = get("/api/MissionList_url/").then(r=>defaultValues.missionList = r).catch(err=>showErrorAlert(err));
    await Promise.all([sysLvl,phase,program,mission]);
}
getSystemLevel_phase();
console.log(defaultValues);
console.log(defaultValues.sysLvlList);

Which logged unidentified when attempting to use dot notation (see image below for reference). When working in the browser console, I would access the data. I believe the promise are fulfilling after the site renders.

What is printed to the console with console.log(defaultValues),console.log(defaultValues.sysLvlList)

Ideally, I would prefer to not have to define the variable outside of the function, but instead set the function to a variable like: const defaultValue = getSystemLevel_phase()

Any help would be appreciated, thank you

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