node.js - 想问下sequelize怎么同步查询啊?因为要查比较多的内容
天蓬老师
天蓬老师 2017-04-17 15:52:51
0
3
641
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
大家讲道理
  • findeOne returns a promise. Does your code above work? ? ? findeOne返回的是一个promise, 你上面的代码执行有用???

const [sysnotice, sysactivity] = await Promise.all([db.sys_news.findOne(),  db.sysactivity.findOne()]);
res.render("index", {
   sysnotice: sysnotice,
    sysactivity:sysactivity
});
  • 如果不用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));
  • If you don’t use await, use the following code

  • rrreee
🎜🎜If there are a lot of arrays, use other methods to return data instead of manually entering the array one by one🎜🎜🎜
洪涛

You can use bluebird’s map method

迷茫

ES6

Using the co moduleco模块

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

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]
    });
})
ES5
adopts the bluebird module🎜 rrreee
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template