reactjs - for循环和等待关键字
问题描述
我有一个使用 await 关键字的 for 循环,它用于检索应用程序以填充 2D 数组:
// initial a 2D array
const filteredGameApps: InstalledApp[][] = [];
for (let i = 0; i < length; i++) {
// get apps by Id
const apps = await getSuggestedGameAppsById(suggestedGameAppIds[i]);
let filteredApps = apps.filter(
app =>
highlyRecommendations.some(highlyRecommendation=> highlyRecommendation.id === app.id)
);
filteredApps = filteredApps.slice(0,6);
filteredGameApps[i] = filteredApps;
}
它不起作用,它仅在删除 for 循环时才起作用,例如:
const filteredGameApps: InstalledApp[][] = [];
const i = 0;
// get apps by Id
const apps = await getSuggestedGameAppsById(suggestedGameAppIds[i]);
let filteredApps = apps.filter(
app =>
highlyRecommendations.some(highlyRecommendation=> highlyRecommendation.id === app.id)
);
filteredApps = filteredApps.slice(0,6);
filteredGameApps[i] = filteredApps;
我在这里错过了什么吗?
解决方案
推荐阅读
- loops - 尝试在 kotlin 中迭代哈希图
- php - 仅当 url 具有特定值时才重定向
- npm - 带有命令行参数的 npm 子脚本
- amazon-web-services - 我可以使用/信任 id_token 来验证请求并在服务器上提取用户信息吗?
- asp.net - ASP.NET 部署问题将图像保存到数据库
- javascript - React Router 更改 URL,但 BrowserRouter 不更改查看的组件
- angularjs - 这个计算器的 Angular.js 平方根
- android - 如何在 WorkManager Android (kotlin) 中仅运行特定的工作人员
- ios - 将图像上传到firebase时出现NSInvalidArgumentException - ios
- c# - 查找并替换字符串中的 100