欢迎选择我的课程,让我们一起见证您的进步~~
findeOne returns a promise. Does your code above work? ? ? findeOne返回的是一个promise, 你上面的代码执行有用???
findeOne
const [sysnotice, sysactivity] = await Promise.all([db.sys_news.findOne(), db.sysactivity.findOne()]); res.render("index", { sysnotice: sysnotice, sysactivity:sysactivity });
如果不用await
await
Promise.all([db.sys_news.findOne(), db.sysactivity.findOne()]).then(result => { const [sysnotice, sysactivity] = result; res.render("index", { sysnotice: sysnotice, sysactivity:sysactivity }); }).catch(error => console.error(error));
You can use bluebird’s map method
ES6
Using the co moduleco模块
co
const co = require('co'); co(function *(){ let sysnotice = yield db.sys_news.findOne(); let sysactivity = yield db.sysactivity.findOne(); res.render("index", { sysnotice: sysnotice, sysactivity:sysactivity }); })
ES5采用bluebird
bluebird
var Promise = require('bluebird'); Promise.all([db.sys_news.findOne(), db.sysactivity.findOne()]).then(function(results){ res.render("index", { sysnotice: results[0], sysactivity:results[1] }); })
findeOne
returns a promise. Does your code above work? ? ?findeOne
返回的是一个promise, 你上面的代码执行有用???如果不用
await
await
, use the following codeYou can use bluebird’s map method
ES6
Using the
co
moduleco
模块ES5
ES5采用
bluebird
adopts the
bluebird
module🎜 rrreee