我的大脑筋疲力尽......请帮忙。
背景是关于Github v3 API get all organizations more than 100我正在继续使用答案。
通过http://host.com/api/v3/organizations?page=1&per_page=100回复标题包含<http://host.otpp.com/api/v3/organizations?page=1&per_page=100&since=318>; rel="next", <http://host.com/api/v3/organizations{?since}>; rel="first"
现在我继续提取318并使用http://host.com/api/v3/organizations?page=1&per_page=100&since=318,现在响应标头包含"<http://host.com/api/v3/organizations?page=1&per_page=100&since=560>; rel="next", <http://github.host.com/api/v3/organizations{?since}>; rel="first""
提取560并使用&#34; http://github.host.com/api/v3/organizations?page=1&per_page=100&since=560&#34;。响应标头为"<http://github.host.com/api/v3/organizations{?since}>; rel="first"
这是我的代码:
function loadAll($scope, $http) {
var data = [];
$http.get(HostgitAPIURL + "organizations?page=1&per_page=100").then(
function(res) {
data.push(res.data);
var link = parse_link_header(res.headers()['link']);
// links[name]=url
while ("next" in link) {
$http.get(link[name]).then(
function(response) {
data.push(response.data);
link = parse_link_header(response.headers()['link']);
}
);
}
$.each(data, function(i, item) {
// process functions
});
$scope.abc = abc;
return abc;
}
);
}
给我异步错误。我已提到Recursive $http.get in for loop但似乎不同的情况。好像我需要1个承诺解决才能打电话到下一个。请问这个递归电话的想法吗?
非常感谢你。