继续收到此错误,但无法弄清楚我的删除功能有什么问题。 “Route.delete()需要一个回调函数,但得到一个[对象未定义]”
const playerController = {
index: (request, response) => {
Player.find({})
.then(player => response.json(player))
.catch(error => console.log(error));
},
create: (request, response) => {
Player.create(request.body)
.then(player => response.json(player))
.catch(error => console.log(error));
},
delete: (request, response) => {
Player.remove(request.params.id)
.then(player => response.json(player))
.catch(error => console.log(error));
//console.log('node function');
}
};
//- - - - = = = = Routes = = = = - - - -
app.get('/players', playerController.index);
app.post('/players', playerController.create);
app.delete('/players/:id', playerController.destroy);
app.all("*", (request, response) => { response.sendFile(path.resolve("./manager/dist/index.html")) });
好的,为了解决这个问题,这里有两个问题:
.playerController.destroy
时,你正在使用playerController.delete
。Player.findByIdAndRemove()
。