我想将请求参数从快速路由器请求传递给函数,该函数将返回相同名称的对象,但是该函数返回参数名称。
我看过函数参数的类型,它是'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 “}]}
实际结果:
“蒙巴萨”
相关分类