很简单,可以从回调内部填充对象符号吗?
诅咒javascript的封闭!
var symbols = {};
markets.find(function(err, markets) {
for(var market in markets) {
symbols[markets[market].symbol] = markets[market].label;
}
});
console.log(symbols);
答案 0 :(得分:0)
async/waterfall是解决此问题的正确方法。由于.find()是异步的,你也可以做一个forEach:
markets.forEach(function(m) {
symbols[m.symbol] = m.label;
});