【发布时间】:2016-09-04 19:56:35
【问题描述】:
在这种情况下我有一个严重的问题。 我通过下面的代码从 github API 获取数据,但由于 github 只允许每页 30 个结果,我想获取所有数据以获得更好的排序选项并将其推送到一个对象数组。下面找到一个代码 这个很好用
$scope.getData = function () {
$http({
method: "GET",
url: api url + pageNum
}).then(function mySucces(response) {
$scope.mydata = response.data;
$scope.isLoading = false;
$scope.result = $scope.mydata.map(function (a) { return { 'name': a.name, 'html_url': a.html_url }; });
}, function myError(response) {
$scope.error = response.statusText;
});
};
但是我想做这样的事情
$scope.getData = function () {
for(var i =0; i<= $scope.pages.length; i++){
$http({
method: "GET",
url: "apiUrl + i
}).then(function mySucces(response) {
$scope.mydata = response.data;
$scope.isLoading = false;
$scope.result = $scope.mydata.map(function (a) { return { 'name': a.name, 'html_url': a.html_url }; });
}, function myError(response) {
$scope.error = response.statusText;
});
};
有什么想法可以做到这一点吗?
【问题讨论】:
-
我在工作中使用 $q.all() 来解决所有承诺。不幸的是,我现在无法访问存储库,也没有在家中进行必要的设置来尝试示例。试着朝那个方向看。
标签: javascript angularjs api get