0
我想從後端服務器獲取用戶詳細信息,我正在獲取詳細信息,但沒有按順序,詳細信息混合在一起。 我的控制器代碼是在這裏如何使angularJs中的「for循環」同步?
function addRecentDetailsToDestination(array) {
for (var i = 0; i < array.length; i++) {
var value = array[i];
userService.RetrieveRecentEduDetail(value.destinationId, function (rResponse) {
if (rResponse.success) {
value.destRecentEducationAvailable = true;
value.destRecentEducationName = rResponse.data.educationName;
userService.RetrieveCollege(rResponse.data.colCode, function (cResponse) {
if (cResponse.success) {
value.destRecentCollegeName = cResponse.data.colName;
} else {
}
});
} else {
value.destRecentEducationAvailable = false;
}
alert(console.log(value.destRecentEducationName));
});
userService.RetrieveRecentProfessionDetail(value.destinationId, function (response) {
if (response.success) {
value.destRecentProfessionAvailable = true;
value.destRecentProfessionRole = response.data.professionRole;
value.destRecentProfessionCompany = response.data.professionCompany;
} else {
value.destRecentProfessionAvailable = false;
}
});
});
}
}
此代碼工作正常,但沒有得到正確的結果,請大家幫我 和我打電話這樣
userService.RetrieveUserConnectionsBySourceId(userId, function (response) {
if (response.success) {
$scope.userConnectionsBySource = response.data;
addRecentDetailsToDestination($scope.userConnectionsBySource);
} else {
FlashService.Error(response.message);
}
});
你能解釋我應該如何實現$ q promises一點點? –