为什么不这样做:
var data =
"q=" + term + "×tamp=" + latest;
var amounts = 2;
url = 'https://api.github.com/search/repositories?q=topic:ruby+topic:rails';
call(url, data, checkForMore);
function call(url, data, callback) {
$http({
method: 'POST',
url: url,
data: data
}).then(function(data){
console.log(data);
console.log('------------');
callback(data);
});
}
function checkForMore(data){
if (amounts > 0){
amounts -= 1;
var newData = "q=" + term +
"×tamp=" + data.SomehowGetLastestTimestamp;
call(url, newData, checkForMore);
} else {
// Save it maybe?
}
}
基本上,有一个在
.then
匿名函数。然后您可以传入数据并检查是否需要调用它。(根据您的情况)。如果你这样做了,那就打电话给
call
再次运行,但更新数据。