为了账号安全,请及时绑定邮箱和手机立即绑定

如何将请求参数从URL传递到返回JavaScript中相同名称的对象的函数?

如何将请求参数从URL传递到返回JavaScript中相同名称的对象的函数?

有只小跳蛙 2021-04-01 14:10:16
我想将请求参数从快速路由器请求传递给函数,该函数将返回相同名称的对象,但是该函数返回参数名称。我看过函数参数的类型,它是'object'类型,但是req.params返回类型字符串。我该如何规避?router.get('/about/:place', (req, res) => {// the object  Mombasa = {    "Destination": "Mombasa",    "Price": 12000,    "Likes": 0,    "Gallery": [{        "image": "https://traveldiscoverkenya.com/wp-content/uploads/2016/05/Mombasa-2-768x499.jpg"    }, {        "image": "https://i2.wp.com/buildesign.co.ke/wp-content/uploads/2017/11/ez.jpg"    }]};// function that returns the object  getPlace = (placeName) => {    return placeName;}  // trying to send reaponse of whole object  res.json(getPlace(req.params.place));});预期结果:{“目的地”:“ Mombasa”,“价格”:12000,“喜欢”:0,“图库”:[{“图像”:“ https://traveldiscoverkenya.com/wp-content/uploads/2016/05/ Mombasa-2-768x499.jpg “},{” image“:” https://i2.wp.com/buildesign.co.ke/wp-content/uploads/2017/11/ez.jpg “}]}实际结果:“蒙巴萨”
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 134 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信