Route.delete()需要一个回调函数但得到一个[对象未定义]

问题描述 投票:0回答:1

继续收到此错误,但无法弄清楚我的删除功能有什么问题。 “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")) });
javascript angularjs node.js mongoose mean-stack
1个回答
1
投票

好的,为了解决这个问题,这里有两个问题:

  1. 当你应该使用.playerController.destroy时,你正在使用playerController.delete
  2. 要按ID删除项目,您应该使用Player.findByIdAndRemove()
© www.soinside.com 2019 - 2024. All rights reserved.