Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.87k stars 601 forks source link

Como posso usar o resultado fora da função xml2js? #575

Closed AlexsandroProjetosOficial closed 4 years ago

AlexsandroProjetosOficial commented 4 years ago

let desenhos = []; svgo.optimize(svg).then((result) => { xml2js.parseStringPromise(result.data).then(async (result1) => { resultado = result1 let pathX = []; functionsAll.extrair(resultado, pathX); for(i in pathX) { desenhos.push({ path: pathX[i] }) } }) })

Não consigo usar o resultado fora.

Tulkdan commented 4 years ago

Nao entendi muito bem a pergunta, voce gostaria de utilizar o xml2js.parseStringPromise fora da promise do svgo.optimize?

(codigo melhor formatado para futuras pessoas verem)

let desenhos = [];
svgo.optimize(svg)
   .then((result) => {
        xml2js.parseStringPromise(result.data)
           .then(async (result1) => { 
                  resultado = result1 
                  let pathX = [];
                  functionsAll.extrair(resultado, pathX);
                   for(const i in pathX) {
                         desenhos.push({ path: pathX[i] })
                    }
                })
          })
AlexsandroProjetosOficial commented 4 years ago

Preciso que a variável resultado possa ser acessdo fora do svgo?  Quando tento fazer isso fica como variável undefined.Enviado do meu smartphone Samsung Galaxy. -------- Mensagem original --------De: Pedro Correa notifications@github.com Data: 29/06/20 16:47 (GMT-03:00) Para: Leonidas-from-XIV/node-xml2js node-xml2js@noreply.github.com Cc: Alexsandro Dev FullStack alexsandrofpf2011@gmail.com, Author author@noreply.github.com Assunto: Re: [Leonidas-from-XIV/node-xml2js] Como posso usar o resultado fora da função xml2js? (#575) Nao entendi muito bem a pergunta, voce gostaria de utilizar o xml2js.parseStringPromise fora da promise do svgo.optimize? (codigo melhor formatado para futuras pessoas verem) let desenhos = []; svgo.optimize(svg) .then((result) => { xml2js.parseStringPromise(result.data) .then(async (result1) => { resultado = result1 let pathX = []; functionsAll.extrair(resultado, pathX); for(const i in pathX) { desenhos.push({ path: pathX[i] }) } }) })

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe. [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/Leonidas-from-XIV/node-xml2js/issues/575#issuecomment-651322756", "url": "https://github.com/Leonidas-from-XIV/node-xml2js/issues/575#issuecomment-651322756", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

Tulkdan commented 4 years ago

Algo assim daria certo? (pelo q entendi)

async function namedFunction(resultado) {
    const desenhos = [];
    const result = await svgo.optimize(svg)
    const result1 = await xml2js.parseStringPromise(result.data)
    resultado = result1 
    const pathX = [];
    functionsAll.extrair(resultado, pathX);
    for(const i in pathX) {
        desenhos.push({ path: pathX[i] })
    }
}
Leonidas-from-XIV commented 4 years ago

As I do not speak (presumably) portuguese, I can't do anything about this report, thus closing.