0
提取數據的函數。呈現模板時的鏈承諾
獲取連接並獲取一些數據。省略了一些代碼。使用該功能
exports.index = function(req, res){
database.executeSQL('SELECT 1 FROM DUAL', [] , {})
.then(function(result) {
res.render('index' , { TITLE : 'Lorem Ipsum Blog' });
})
.catch(function(err) {
next(err);
});
};
我index
控制器在我index
航線使用
function executeSQL(sql, bindParams , options) {
return new Promise(function(resolve, reject) {
...
resolve(result);
});
}
控制器。
我需要至少調用我的executeSQL函數兩次。只有在他們兩人都完成之後,我纔想撥打res.render
併發送我提取的數據。
我該如何鏈接它們? 我甚至需要鏈接它們嗎?我可以只是以異步方式執行它們,一旦完成後我就打電話給res.render
。
怎麼樣'Promise.all(ARR).then'? – Rayon
@RayonDabre當我在result1上運行console.log時,它返回undefined。我的渲染功能沒有從這2個承諾中得到結果。 – Paran0a
我的壞...請參考:https://jsfiddle.net/rayon_1990/Lson6f62/1/ – Rayon