I'd like to use map()
in NodeJS to change items of my array before rending an EJS template.
However, sometimes the map()
is not finished before the render and I get an error 500...
My code :
var newCards = cards.map(function(card) {
switch(card.display) {
case 'number':
dbConnexion.query(card.query).success( function(results) {
card.results = results.length;
});
break;
case 'table':
dbConnexion.query(card.query).success( function(results) {
card.results = results;
});
break;
}
return card;
});
response.render('myview', {
newCards: newCards
});