下面的 java-script 代码上下文值在嵌套循环内变得未定义。但在嵌套循环外,值正确显示。
请帮助显示循环内的上下文值。
module.exports = function (options = {}) {
return async context => {
const { data } = context;
context.app.service('emplist').find({
query: { empId: { $in: ["12321"] } },
paginate: false,
}).then(result => {
console.log('firstname_Inside-->',context.data.firstname);
}).catch((error) => {
console.log(error);
});
console.log('firstname_Outside-->',context.data.firstname);
return context;
};
};
输出:-
//here value is undefined
firstname_Inside-->undefined
//here value is properly showing
firstname_Outside-->sam