var suc=0;
var failed=0;
var tot=0;
var body={};
var f = (function() {
for (var i=0; i< $scope.data.length; i++) {
(function() {
body = {
"data": {
email:$scope.data[i].mail,
firstName:$scope.data[i].name,
};
tot=tot+1;
if ($scope.group)
body.group = $scope.group;
$http({
url: API.toUrl('api/xxxxx/xxxxx'),
method: 'POST',
data: body
}).then(function(response) {
if (response.status == 200) {
suc = suc + 1;
}
},
function(error) {
if (error.status == 400) {
failed = failed + 1;
}
})
})(i);
}
})();
console.log("Data: "+tot+" Success: "+suc+" Failed: "+failed);
当我在控制台中显示0时,vars成功并失败 如果我将变量显示在循环中并且在IF语句中正常工作。
有什么想法吗?感谢