0
我用快递,在某处,我需要做到这一点如何使一个很好的功能结构
- 从发件人一些API JSON
- 从接收机一些API JSON得到得到
- 渲染页面与他们两个
所以我RLY无法理解如何构建这个功能...我的意思是
router.get('/', function (req, res, next) {
res.render('nodes/index', {senders: helper.getServices(), receivers: helper.getReceivers()}
我的功能看起来像
this.getSenders =() => {
var options = { ... some opts }
request(options)
.then(function (body) {
return body
})
.catch(function (err) {
if (err) {
console.log(err)
}
})
}
采用这种结构的页面呈现之前将数据从函数返回... 应该如何组织我的代码,以避免这种情况?