有如下代码:
let result = {
data: {
values: [],
}
};
try {
let baseInfo = await baseinfoModel.getSystemInfo();
if (baseInfo === null) {
return null;
} else {
baseInfo.forEach(function (doc) {
result.data.values.push({
objectid: doc._id,
system: doc.system,
});
}, function (err) {
if (err) {
throw err;
}
})
return result;
}
} catch (err) {
throw err;
}
问题来了,forEach里保存result数据,但外面的定义的result是没有改变的,怎样才能把forEach的数据传递到外面变量?
这样是可以改到外面的
result
变量的。因为不知道getSystemInfo()
里面具体执行了什么,我也没法判断。你先确定一下走的是if
还是else
。