得到错误:TypeError:无法读取未定义的属性'then'

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

我正在创建一个电子商务网站,同时在检索产品详细信息时收到此错误!

exports.getProduct = (req, res, next) => {
  const prodId = req.params.productId;
  return Product.findById(prodId).then(([rows])=>{
    res.render('shop/product-detail', {
      product: rows[0],
      pageTitle: rows.title,
      path: '/products'
    });
  })
  .catch(err=> console.log(err));
};
node.js
1个回答
0
投票

在调用findById函数之前,需要检查参数的有效性,因为我没有对此进行检查并且遇到了此错误。

© www.soinside.com 2019 - 2024. All rights reserved.