【发布时间】:2020-12-02 04:41:03
【问题描述】:
我正在尝试做一个基本的删除 todo 方法但没有成功。不知道为什么会出现这个错误希望得到帮助。 错误: (节点:6416)UnhandledPromiseRejectionWarning:TypeError:分配给常量变量。 在deleteTodo
代码:
const deleteTodo = async (req, res, next) => {
const { id } = req.body;
DUMMY_PLACES = DUMMY_PLACES.filter((p) => p.id !== id);
res.status(200).json({ message: "Deleted " });
};
DUMMY_DB
const DUMMY_PLACES = [
{
id: 01,
todo: "thats my first test to do",
enable: false,
},
{
id: 02,
todo: "thats my second test to do",
enable: false,
},
{
id: 03,
todo: "thats my third test to do",
enable: false,
},
];
postman 中的 DELETE 请求:
{
"id": 3
}
【问题讨论】:
-
"赋值给常量变量"–
DUMMY_PLACES是一个常量变量。
标签: javascript node.js postman backend