Getting Data from Multiple .then Statements in Javascript

By Forrest Smith - Drempd.com

I always have a hard time pulling data through multiple .then statements in javascript. This method works sufficiently well. Basically, define an array/object, and then as data is collected, add content to that array. All of the collected content should be available in the final .then statement. Something like this (all the data is collected into the viewData variable):

data = {};
data['table'] = 'tableName';

var viewData = {};
viewData['table'] = data;

get_table_columns(data['table'])
.then(function(columnData){
viewData['columns'] = columnData;
})
.then(get_row_data)
.then(function(rowData){
viewData['values'] = rowData;
console.log(viewData);
});