【发布时间】:2013-12-08 19:58:35
【问题描述】:
我正在尝试在名为“城市”的项目列表中添加一些额外的变量,然后再将其返回到我的新sails.js 应用程序中的客户端。 Sails.js 使用 Underscore.js 进行基本的函数式编程。
这是我目前使用的 _.each。 (我首先尝试使用 _.map 并返回 User 但这也不起作用)。
控制台正确记录了每个单独的用户,但在 _.each 案例“[]”中,cities_with_count 为空,而在 _.map 案例“[ 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
});
});
【问题讨论】:
标签: javascript node.js underscore.js sails.js