我想使用以異步的NodeJS()加成,但它不工作...異步方法的NodeJS
我的代碼:
結果的total
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});
});
});
:NaN的
與你的問題無關,但不應'callback();'向上移動一個塊?然後當你的查詢和循環完成時它會被調用。現在'async.parallel'的回調可能會在查詢有時間完成之前執行。 – RikkusRukkus 2014-10-10 09:13:02