[英]I am unable to run a loop dependent on variable from function
好吧,所以我花了最后一天試圖弄清楚一些事情,我是編碼的新手,很抱歉。 我目前正在開發一個要求JSON的漫游器,這是到目前為止的代碼
const request = require('request');
const bodyParser = require('body-parser');
global.count = 10;
for (var i = 1; global.count === 10; i++) {
var options = {
url: 'https://www.the100.io/api/v1/groups/2127/users?page=' + i, //Returns 10 entries per page, so loop is to navigate pages
headers: {
'Authorization': 'Token token="Hidden for Privacy"'
}
}
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body); //Also need a way to append to info as to add on as the loop progresses, still need to look that up though
console.log(JSON.stringify(info, null, 1)); //Logs the body
global.count = info.length; //Will return the value 10, until there are no more entries and then will terminate loop
}
}
request(options, callback);//Sends request
}
//It just keeps running the loop and doesn't execute the request at the bottom which is what will make the loop terminate, I've tried many things with
//callbacks and nothing has worked so far
我似乎無法能夠使循環正常運行,我也不想求人,但我堅持我很傷心地說。 提前謝謝。
我覺得這個問題有些什么困惑,並解釋清楚???
在您的for循環寫作中,不斷重復您想要的東西。
我認為應該用於頁面加載的導航(每頁包含10個)
global.count = 10;
for( var i = 1; i< =global.count; i++)
{
-- Write Your code here ---
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.