此代码块导致标题为eslint的规则出错。我试图弄清楚如何删除迭代依赖项,但我不太清楚。任何帮助将不胜感激。
for (let i = 0; i < areaRes.hits.hits.length && i < MAX_PAGE_LIMIT; i += 1) {
const record = areaRes.hits.hits[i];
const snapshot = await listings.forBoundary(record, filter, listingType,
status, roleId, roleType);
areaResponseArr.push({ ...snapshot });
}
答案 0 :(得分:2)
您可以将诺言放入循环中,并在循环外使用await
,例如:
const promises = [];
for (let i = 0; i < areaRes.hits.hits.length && i < MAX_PAGE_LIMIT; i += 1) {
const record = areaRes.hits.hits[i];
promises.push(listings.forBoundary(record, filter, listingType, status, roleId, roleType));
}
const areaResponseArr = await Promise.all(promises);