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

149
Visualizações
encadenamiento de nodos y luego no retorno

Soy nuevo en la función async y estoy tratando de encadenar alguna función, pero no puedo entender por qué no puedo devolver la última llamada.

 var container = { Login: '', sign_up_text: '', forget_password: '', login_button: '' } var lang = 'de-DE' var langID = 1 async function getVars (key, lang){ return db.localization.findOne({ where: { key: key, lang: lang } }) } async function getLangID (lang){ return db.localGroups.findOne({ where: { i10s: lang }, attributes: ['id'] }) } async function getLocalvars (container, lang){ var newcontainer = container for (let key in container) { console.log(lang) await getVars(key, lang) .then(data => { newcontainer[data.key] = data.value; }) } return newcontainer; } async function desprate() { getLangID(lang) .then(langdata => { getLocalvars(container, langdata.id) .then(data => { console.log(data); return data; }) }) } console.log(desprate());

Ni siquiera una promesa aparece en el registro ;(

¡Gracias!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Le daré una oportunidad a esto. No he probado esto, pero intentaré alcanzar los conceptos clave aquí en los comentarios.

 var container = { Login: '', sign_up_text: '', forget_password: '', login_button: '', }; var lang = 'de-DE'; var langID = 1; async function getVars(key, lang) { return db.localization.findOne({ where: { key: key, lang: lang, }, }); } async function getLangID(lang) { return db.localGroups.findOne({ where: { i10s: lang, }, attributes: ['id'], }); } async function getLocalvars(container, lang) { var newcontainer = container; // since you're iterating over an object you will have to await all the promises that result in the loop await Promise.all( Object.keys(container).map(async (key) => { const data = await getVars(key, lang); // since this is an async function you can just await it rather than chaining it with then newcontainer[data.key] = data.value; }) ); return newcontainer; } async function desprate() { // let's again take advantage of async/await here const langdata = await getLangID(lang); const data = await getLocalvars(container, langdata.id); console.log(data); return data; } console.log(desprate());
about 4 years ago · Juan Pablo Isaza Relatório
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