這是我的代碼片段,我在哪裏使用Express路由器和Mongoose模型。無法在expressjs中訪問參數router.delete
我無法訪問id parm。
router.delete('/task/:id', function (req, res) {
Task.remove({ did: req.parms.id }, (err) => {
if (err) {
res.send(err);
}
});
});
這是我收到
TypeError: Cannot read property 'id' of undefined at F:\NS\routes\tasks.js:11:33 at Layer.handle [as handle_request] (F:\NS\node_modules\express\lib\router\layer.js:95:5) at next (F:\NS\node_modules\express\lib\router\route.js:131:13) at Route.dispatch (F:\NS\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (F:\NS\node_modules\express\lib\router\layer.js:95:5) at F:\NS\node_modules\express\lib\router\index.js:277:22 at param (F:\NS\node_modules\express\lib\router\index.js:349:14) at param (F:\NS\node_modules\express\lib\router\index.js:365:14) at Function.process_params (F:\NS\node_modules\express\lib\router\index.js:410:3) at next (F:\NS\node_modules\express\lib\router\index.js:271:10) at Function.handle (F:\NS\node_modules\express\lib\router\index.js:176:3) at router (F:\NS\node_modules\express\lib\router\index.js:46:12) at Layer.handle [as handle_request] (F:\NS\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (F:\NS\node_modules\express\lib\router\index.js:312:13) at F:\NS\node_modules\express\lib\router\index.js:280:7 at Function.process_params (F:\NS\node_modules\express\lib\router\index.js:330:12) at next (F:\NS\node_modules\express\lib\router\index.js:271:10) at F:\NS\node_modules\express-validator\lib\express_validator.js:291:5 at Layer.handle [as handle_request] (F:\NS\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (F:\NS\node_modules\express\lib\router\index.js:312:13) at F:\NS\node_modules\express\lib\router\index.js:280:7 at Function.process_params (F:\NS\node_modules\express\lib\router\index.js:330:12)
謝謝..它工作正常 –