【发布时间】:2018-04-25 13:41:46
【问题描述】:
我有以下功能,旨在删除表中的所有元素。
每行的key字段存储在rowKeys中,当前内容为["www.google.com", "www.youtube.com", "www.facebook.com"]
async onAfterDeleteRow(rowKeys) {
for(let i = 0; i < rowKeys.length; i++){
console.log(rowKeys.length); //3
console.log(rowKeys[i]); //www.google.com
this.setState({
deleting: true,
jsonBefore: this.state.json
});
console.log("About to post"); //About to post
const response = await
fetch('/delete-cert', {
headers: {
'Content-Type': 'application/json'
},
method: 'POST',
body: JSON.stringify({deletedCert: rowKeys[i]})
});
console.log("Post done");
const body = await response.text();
if (response.status !== 200) throw Error(body.message);
}
console.log("Left For Loop");
}
以下 3 行打印到控制台:
3
www.google.com
About to post
但它不会打印 2 行:
Post done
Left For Loop
它成功删除了www.google.com,但没有删除数组中的下两个项目,知道为什么这个迭代不起作用吗?
【问题讨论】:
-
首先将这些等待包装在 try catch 块中
标签: node.js reactjs rest post fetch