我想在 NodeJS 中使用 Async() 进行添加,但它不起作用......
我的代码:
var id = request.params.id;
var self = this;
var total;
var asyncTasks = [];
asyncTasks.push(function(callback){
self.orderDao.getAllOfUser(id).success(function (orders) {
orders.forEach( function(order){
total = total + order.price; // here I'd like to make the addition
console.log(total);
});
});
callback();
});
async.parallel(asyncTasks, function(){
self.orderDao.getAllOfUser(id).success(function (orders) {
response.render('order/index', {orders: orders, total: total});
});
});
结果total
:NaN