I'm trying to tack on a few extra variables to a list of items called "cities" before it goes back to the client in my new sails.js app. Sails.js uses Underscore.js to do basic functional programming.
here is what I have currently using _.each. (I first tried to use _.map and return User but that didn't work either).
The console correctly logs each individual user, but cities_with_count is empty in the _.each case "[]" and two undefined's in the _.map case "[ undefined undefined ]"
User.findByIdIn(user_ids).then(function(users){
var users_with_counts = []
_.each(users, function(user) {
Candy.count({ type: "yummy").then(function(candy_count){
user.candy_count = candy_count
console.log(user);
users_with_count.push(user);
});
});
console.log(users_with_count);
res.view({
users: users_with_count
});
});