gpt4 book ai didi

node.js - 试图将 sequelize 查询的结果传递给 pug

转载 作者:行者123 更新时间:2023-12-03 22:40:32 25 4
gpt4 key购买 nike

我正在尝试将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com