我有以下代码。prices
尽管成功检索了ustock.unitprice
.
getLatestMarketPrices: function(username, callback) {
var prices = [];
db.find('portfolio', {user: username}, function(err, stocks) {
for(var i = 0; i < stocks.length; i++) {
module.exports.getQuote(stocks[i].stock, function(err, ustock) {
console.log(ustock.unitprice); // Retrieves 1.092
prices.push(ustock.unitprice); // Should push to prices array?
});
}
console.log(prices); // Prices is still [] despite earlier push.
callback(null, prices);
});
},
这是范围界定问题吗?我不太确定为什么prices
不推到。
非常感谢。