I have declared the async before function,but it still notice that The ‘await’ operator can only be used in an ‘async’ function
async function Refresh(regListResult) {
$(".dfxContent").each(function (index) {
if (index >= 13 && index < 37) {
var regComment = $(this).nextAll().eq(4).html();
if (-1 !== regComment.indexOf("1")) {
// 在这里加一个读通道位置的函数
var chnPlace = ChnPlaceGet(a, b, c);
await new Promise(resolve => setTimeout(resolve, 1000));
var chnPlaceData = '两者应匹配,' + chnPlace;
RefreshAnother(Data, index);
$(this).html(a + b + c);
}
}
});
}
How can I make the statement valid?
3
Answers
Perhaps you mean something closer to this
Your error is because you didn’t declare the async function correctly. To fix this error you have to declare the async to right first function which includes await keywords.
So please change
to
and try again.
each is expecting an async function. But each is not awaited, so is better if you map Promises, and you wait them after: