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

213
Visualizações
JS compiling information from looped Promises? (w/ Tableau API)

I am trying to use the tableau JS API https://help.tableau.com/current/api/js_api/en-us/JavaScriptAPI/js_api_ref.htm to gather all the data from every "worksheet" object to do some more complex behavior but I am having trouble understanding how to use the promises within loops. I've used when().then() with ajax before, but not much other experience with promises.

Worksheet -> Marks -> Pairs -> key/value
  • I start with a sheets object variable that is instantiated with "worksheets".
  • I loop through each "worksheet" to get the "marks" which has data key/value "pairs".
  • I save every data pair into another object variable markpairs_object.
  • The part I have issues with is figuring out how to use the final object variable markpairs_object because it's always empty at execution time.
sheets[window][section] = tableau "worksheets".

markpairs_object = [];
for(var section in sheets){
    for(var window in section){
        // ASYNC getting marks
        sheets[section][window].getSelectedMarksAsync().then(function(marks){
            for(var markIndex=0; markIndex<marks.length; markIndex++){
                var pairs = marks[markIndex].getPairs(); // I don't think this is ASYNC
                for(var pairIndex=0; pairIndex<pairs.length; pairIndex++){
                    var pair = pairs[pairIndex];
                    // save pair info to an overall object variable
                    markpairs_object[pair.fieldName] = pair.formattedValue;
                }
            }
        });
    }
}

//loop through object variable to make sure it worked
whatever I do here shows empty

I've tried:

  • using callbacks
  • moving different things into their own functions but didn't understand how to implement await/async here
  • another .then() after the getSelectedMarksAsync().then() but that would only get the pairs for one worksheet at a time if it worked (it didn't)
  • creating flag variables to try to indicate when pairs data has been saved

etc. but the object is always empty at the time of execution and I could not understand how to get this to work correctly.

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