我用的是续写,我要按位置的价值排序。我认为后遗症会随机产生结果。
这里是我的查询:
router.post("/", (req, res) => {
const value = req.body.value
Titles.findAll({
where:
{ [Op.or]: [
{title: { [Op.iLike]: '%' + value + '%'}},
{titleLink: { [Op.iLike]: '%' + value + '%'}}
]
},
attributes: ['id', 'title', 'titleLink', 'entryCount'],
///limit: 10,
}).then(result => {
res.json({'titles': result})
})
//res.send({results: req.body})
})它给出的结果如下
值:测试
结果:
结果(我想要):
发布于 2019-12-29 11:20:52
如果Titles有一个position字段,那么您可以使用https://sequelize.org/master/manual/querying.html#ordering中提到的order属性(或者使用id字段):
router.post("/", (req, res) => {
const value = req.body.value
Titles.findAll({
where:
{ [Op.or]: [
{title: { [Op.iLike]: '%' + value + '%'}},
{titleLink: { [Op.iLike]: '%' + value + '%'}}
]
},
attributes: ['id', 'title', 'titleLink', 'entryCount'],
order: [['position', 'ASC']],
///limit: 10,
}).then(result => {
res.json({'titles': result})
})
//res.send({results: req.body})
})发布于 2019-12-30 20:05:48
在我的例子中,它解决了
从“后缀”导入{ Sequelize };
前:order:'created_at'
后:order: Sequelize.literal('created_at DESC'),
看上去不错,2020年快乐
https://stackoverflow.com/questions/59515681
复制相似问题