2
I’m accessing the API of Trello, but I came across the following problem:
Access Trello information by 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 go through all these lines with the for
, within the loop, assign each row to a variable x
and call a function that aims to get the number of cards of that row. 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 vector numberCardsByList
after the end of the search on the trello, 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’m aware it’s because of the asymchronism, but I can’t solve it.
Perfect, thank you
– Jonathan