我在函数内部启动了几个回调函数。我不希望父函数在所有回调函数返回它的响应之前返回任何值。
我试过这个,没有任何运气:
function getList(userList) {
let tempArray = []
let allAboard = false
userList.map((users, usersIndex) => {
users.map((user, userIndex) => {
HTTP.get(SOME API CALL, function(response){
tempArray.push({'user': user.id, 'elements': response.data})
if (tempArray.length === (userList.length * users.length)){
allAboard = true
}
})
})
})
while(!allAboard) {
if (allAboard) {
break
}
}
return tempArray
}
知道如何使这项工作吗?