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)
}
})
}
採用這種結構的頁面呈現之前將數據從函數返回... 應該如何組織我的代碼,以避免這種情況?