function setUsersDefinitions(data, userID){
let users = new Array();
return new Promise((resolve)=>{
data.forEach(el => {
if (el.id_adder === userID) {
getUserName(el.id_added).then(u => {
users.push({
username: u,
locked: el.locked !== null,
canUnlock: el.locked === userID,
id: el.id_added
})
}).catch(e=>{
console.log(e);
})
} else {
getUserName(el.id_adder).then(u=>{
users.push({
username: u,
locked: el.locked !== null,
canUnlock: el.locked === userID,
id: el.id_adder
})
}).catch(e=>{
console.log(e);
})
}
})
resolve(users);
})
}
问题是,当我尝试对生成的项目执行 console.log 时,它可以工作,但是当它调用 Array.push 方法时,它会忽略该命令。我究竟做错了什么?提前致谢。
繁星淼淼
相关分类