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
sheets object variable that is instantiated with "worksheets".markpairs_object.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:
etc. but the object is always empty at the time of execution and I could not understand how to get this to work correctly.