Javascript TypeError:无法读取动态参数节点js中未定义的属性“id”

Javascript TypeError:无法读取动态参数节点js中未定义的属性“id”,javascript,node.js,express,server,Javascript,Node.js,Express,Server,我试图在节点js中创建一个动态参数,其中的链接/eshop/edit/1111将带您编辑特定产品,但每次我尝试在/edit/I get TypeError之后添加产品代码时:无法读取未定义的属性“id” 这是我的服务器代码 这里的错误是处理程序的参数顺序错误。它应该是req,res=>的顺序 完整代码为: router.get('/edit/:id', async (req, res) => { let id = req.params.id; let data =

我试图在节点js中创建一个动态参数,其中的链接/eshop/edit/1111将带您编辑特定产品,但每次我尝试在/edit/I get TypeError之后添加产品代码时:无法读取未定义的属性“id”

这是我的服务器代码


这里的错误是处理程序的参数顺序错误。它应该是req,res=>的顺序

完整代码为:

router.get('/edit/:id', async (req, res) =>
{
    let id = req.params.id;
    
    let data = {
        title: `Edit product ${code} | BuckStar`,
        pageTitle: `Edit product ${code}`,
        product: id
    };

    data.res = await results.editProduct(id, req.body.category, req.body.name, req.body.description, req.body.price, req.body.amount, req.body.amount, req.body.location);

    res.render("page/create-edit", data)
});

这里的错误是处理程序的参数顺序错误。它应该是req,res=>的顺序

完整代码为:

router.get('/edit/:id', async (req, res) =>
{
    let id = req.params.id;
    
    let data = {
        title: `Edit product ${code} | BuckStar`,
        pageTitle: `Edit product ${code}`,
        product: id
    };

    data.res = await results.editProduct(id, req.body.category, req.body.name, req.body.description, req.body.price, req.body.amount, req.body.amount, req.body.location);

    res.render("page/create-edit", data)
});

我相信您交换了响应和请求参数

有关Express文档,请参阅下面的链接


我相信您交换了响应和请求参数

有关Express文档,请参阅下面的链接


我认为正确的代码是这样的,因为请求应该在响应之前出现

router.get('/edit/:id', async (req,res ) =>
{

});

我认为正确的代码是这样的,因为请求应该在响应之前出现

router.get('/edit/:id', async (req,res ) =>
{

});

这是如何被接受的答案?这基本上是两个小时前提交的答案的副本。这是怎么被接受的答案?这基本上是两小时前提交的答案的副本。