我先发送数据,然后就没有问题了,但是当我想更新的时候,我可以删除根对象的id,但是我不能删除列表中对象的id,有什么想法吗?
const handleSubmit = async (values: any) => {
setIsLoading(true);
if (!id) {
usersService
.create(values)
.then((response) => {
saved(response.data._id);
})
.catch((error) => {
message.error(`${t("error")} ${error.response.data.message}`);
})
.finally(() => {
setIsLoading(false);
});
}
if (id) {
const formData = { ...result, ...values };
console.log(formData);
delete formData._id;
delete formData.createdAt;
delete formData.updatedAt;
delete formData.List.map((x : any) => x._id) // this didn't work
delete formData.enrolledCourses;
delete formData.isProfileCompleted;
usersService
.update(id, formData)
.then(() => {
saved();
rowHighlight(id);
})
.catch((error) => {
message.error(`${t("error")} ${error.response.data.message}`);
})
.finally(() => {
setIsLoading(false);
});
}
};
我尝试了map函数和forEach函数。我尝试删除返回值 函数的内部和外部都找过了,但没找到
1条答案
按热度按时间efzxgjgh1#
您需要Map每个列表项并删除它们的id属性,如下所示: