如何将参数传递到那时
当调用下面的功能时,我将不确定Q。我不知道该怎么办。请帮忙。谢谢。我尝试将Q作为参数传递到当时,但它不起作用。
myfunction = () =>{
sendFetch(
`http://api.com`,
GET
).then((response)=>{
for (var i = 0; i < response.data.length; i++) {
processed_data.push(response.data[i].description);
}
for (var q = 0 ; q < array.length; q++)
{
sendFetch(
`api.com`,
GET
).then((response)=>{
console.log(q)
})
}
})
}
When call the function below I am getting undefined for q. I do not know what to do. Please help. Thank you. I have tried passing q into then as a parameter but it does not work.
myfunction = () =>{
sendFetch(
`http://api.com`,
GET
).then((response)=>{
for (var i = 0; i < response.data.length; i++) {
processed_data.push(response.data[i].description);
}
for (var q = 0 ; q < array.length; q++)
{
sendFetch(
`api.com`,
GET
).then((response)=>{
console.log(q)
})
}
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议研究范围和“ var”和“ let”之间的差异。
也有异步和承诺。
我们不再使用“ var” s,并且要谨慎声明具有等效名称的变量。您正在同一范围中使用“响应”。
I suggest studying scopes and the difference between "var" and "let".
Also async and promises.
We don't use "var"s anymore and be careful about declaring variables with equals name. You are using "response" in the same scope.
您可以等待sendfetch而不是使用然后捕获。
尝试一下:
You can await the sendFetch instead of using then catch.
Trye this: