我正在尝试将 sequelize 查询的搜索结果传递给 pug,但它不起作用
res.render('search',{
stack_holder:find_stack_holder(),
});
function find_stack_holder(){
return db.poregister.findAll({
attributes: [[Sequelize.fn('DISTINCT', Sequelize.col('stack_holder')), 'stack_holder']],
})
}
然而,pug 得到了 promise 而不是实际数据。当需要实际数据时, promise 不应该自行解决吗?
最佳答案
findAll
返回 Promise ,因此,您需要执行以下操作:
const findAllPromise = find_stack_holder();
findAllPromise.then(function(result) {
res.render('search',{
stack_holder: result,
});
});
function find_stack_holder() {
return db.poregister.findAll({
attributes: [[Sequelize.fn('DISTINCT', Sequelize.col('stack_holder')), 'stack_holder']],
});
}
关于node.js - 试图将 sequelize 查询的结果传递给 pug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48316695/