【发布时间】:2018-08-07 05:52:44
【问题描述】:
我有 Angular js 应用程序。我正在尝试使用 angular.forEach 解析 json 数组。它表现出奇怪的行为。
当我试图控制它时,它正在显示数据,但是当我试图用长度来控制它时,它显示长度为 0。
我只想在循环外输出。我怎样才能做到这一点?
谁能帮我解决这个问题?
function loadRelease() {
$scope.datas.releaseData = [];
angular.forEach($scope.datas.repositoryData, function(value, key) {
GitHubService.getDevMasterReleaseDate(value.url)
.then(function(responseRepo) {
var dataToOperate = [];
var dataJson = {
'repoName': value.name
, 'masterArray': []
, 'devArray': []
}
angular.forEach(responseRepo.data, function(value, key) {
if (value.target_commitish == 'master') {
dataJson.masterArray.push(value);
} else {
dataJson.devArray.push(value);
}
});
$scope.datas.releaseData.push(dataJson);
}, function(error) {
});
});
console.log($scope.datas.releaseData);
console.log('length :: ' + $scope.datas.releaseData.length);
}
控制台:
【问题讨论】:
-
将控制台移入
then
标签: javascript angularjs json for-loop