首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我无法运行依赖于来自函数的变量的循环

我无法运行依赖于来自函数的变量的循环
EN

Stack Overflow用户
提问于 2016-11-07 12:55:08
回答 1查看 41关注 0票数 0

好的,我花了最后一天的时间试图弄清楚一些事情,我对编码是相对的新手,所以如果弄得一团糟,我很抱歉。我目前正在开发一个请求JSON的机器人,以下是我到目前为止拥有的代码

代码语言:javascript
复制
 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

我似乎无法让循环正常运行,我不想寻求帮助,但我很遗憾地说,我被卡住了。提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2016-11-07 13:11:57

我觉得有些困惑的问题和解释清楚了吗?

在你的写作中,for循环是不断重复的,你想要的是其他的东西..

在我看来,它应该是用于页面加载的导航(每个页面包含10个)

代码语言:javascript
复制
global.count = 10;
for( var i = 1; i< =global.count; i++)
{
 -- Write Your code here ---
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40458085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档