我的应用程序遇到严重问题,我使用AngularJs。 我用“for”来遍布我的资源。为每个ressource我做$ http.get有关于这个ressource的数据。 我的问题是我的程序不等待获得$ http.get的响应然后$ http.get()适用于我的上一个ressource。
我首先看到我的ressource的所有警报,然后警告('新用户')完成。
谢谢;)
$scope.loadPlanning = function() {
//var tasksRessource = [];
//tasksRessource.push({name: 'Go-liiive', color: '#93C47D', from: new Date(2013, 10, 23, 1, 0, 0), to: new Date(2013, 10, 25, 24, 0, 0)});
//tasksRessource.push({name: 'Go-live', color: '#93C47D', from: new Date(2013, 10, 27, 1, 0, 0), to: new Date(2013, 10, 29, 24, 0, 0)});
var data = [];
for(var i = 0; i < $scope.ressources.length; i++) {
var nameR = $scope.ressources[i].firstName + ' ' + $scope.ressources[i].lastName;
alert(nameR);
// On récupère la liste des visites clients associé a cet utilisateur
//Visiteclient.getByRessource({id: $scope.ressources[i].id}, function(result) {
$http.get("api/api/visiteclientsbyressource/" + $scope.ressources[i].id).success(function(result) {
var tasksRessource = [];
$scope.visiteclietest = result;
for (var p = 0; p < $scope.visiteclietest.length; p++) {
var name = result[p].name;
var dateDebu = result[p].date;
var dateFin = result[p].date;
tasksRessource.push({name: name, color: '#93C47D', from: new Date(dateDebu), to: new Date(dateFin)});
}
$scope.pushData(tasksRessource);
});
$scope.pushData = function(taskr) {
alert ('new user');
data.push({name: nameR,classes: "custom-row", tasks : taskr});
console.log({name: nameR,classes: "custom-row", tasks : taskr});
}
}
}