问题描述
我正在尝试创建一个Express搜索结果页面,我几乎在那里,但是无法理解为什么我无法从结果docs
内的控制器访问var res.render
。 js。我可以用另一种方法访问,即我可以从控制器内部的results.js访问cityCode
,但不能从路由器docs
内部访问res.render
,为什么?
我需要访问results.js docs = response.data;
内部的res.render
来建立我的页面。
/routes/result.js
const express = require('express');
const router = express.Router();
router.get('/results',(req,res,next) => {
const cityCode = req.query.cityCode;
const searchAmadeus = require('../controllers/amadeusControl.js');
searchAmadeus.findNew(cityCode,(docs) => {
});
res.render('results',{
title: 'We Found Some Great Deals',// list: [5,2,3,4,4],// as a test this works
list: docs,// but I need to access this coming from the controller
},);
},);
module.exports = router;
/controllers/amadeusControl.js
module.exports = {
findNew: function(cityCode,docs) {
const Amadeus = require('amadeus');
const amadeus = new Amadeus({
'clientId': process.env.AMADEUS_CLIENT_ID,'clientSecret': process.env.AMADEUS_CLIENT_SECRET,});
console.log('Before api call',cityCode);
amadeus.shopping.hotelOffers.get({
cityCode: cityCode,}).then(function(response) {
console.log('After api call',cityCode);
docs = response.data;
// test // console.log('docs',docs;
return docs;
}).catch(function(error) {
console.log(error.response);
console.log(error.response.request);
console.log(error.code);
});
}};
提前谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)