I'm accessing the Trello API , but I came across the following problem:
Access the Trello information, obtaining the id of each existing queue, the code is as follows:
var x;
var numberCardsByList = [];
trello.get("/1/boards/[idBoard]/lists/all", function(err, data) {
if (err) throw err;
console.log("Quantidade de Filas: " + data.length);
for(var i=0; i<data.length; i++){
x = data[i];
findNumberCards(x);
}
});
As you can see, after I get the size, I run through all those queues with for
, inside the loop, assign each queue to a x
variable, and call a function that aims to get the number cards of that queue. The code to get the number of cards is as follows:
trello.get("/1/lists/"+x.id+"/cards", function(err, dados){
if(err) throw err;
console.log("A fila com nome: " + x.name + " tem " + dados.length + " cards");
numberCardsByList[x.name] = dados.length;
});
So far so good, however, when I try to access the numberCardsByList
vector after the end of the trello search, it returns undefined:
var x;
var numberCardsByList = [];
trello.get("/1/boards/[idBoard]/lists/all", function(err, data) {
if (err) throw err;
console.log("Quantidade de Filas: " + data.length);
for(var i=0; i<data.length; i++){
x = data[i];
findNumberCards(x);
}
});
console.log(numberCardsByList);
I am aware that it is because of asynchronism, but I can not solve it.