我想将对象添加到promise中的局部变量,但是该变量在其中无法访问,这里是代码,请关注注释"此处可访问且无法在此处访问":
var dfs = [];
var createDFs = function(item, index) {
var country = item._id;
item.country = (countries[0][country.toUpperCase()]);
var findComps = Complete.find({'country': country});
findComps.then(function(comps) {
item.complete = comps;
//dfs.push(item); //doesn't work here
});
dfs.push(item); //works here but item.comps not accessible
};
data.forEach(createDFs);