我的 sails 应用程序遇到排序问题:
我正在尝试使用水线对对象进行排序,但它似乎被排序为字符串而不是整数。
这是我的项目:
module.exports = {
attributes: {
id:{
type:"int",
required:true
},
id_scenario:{
type:"int",
required:true
},
id_commande:{
type:"int",
required:true
},
ordre:{
type:"int"
}
}
};
这是我的代码:
ScenarioCommande.find()
.where({ id_scenario: idScenario })
.sort({ordre: 'ASC'})
.exec(function(err, scenariocommande) {
res.json(scenariocommande);
});
这是输出:
{
"id": "30",
"id_scenario": "12",
"id_commande": "6",
"ordre": "1",
"createdAt": null,
"updatedAt": null
},
{
"id": "37",
"id_scenario": "12",
"id_commande": "18",
"ordre": "10",
"createdAt": null,
"updatedAt": null
},
{
"id": "31",
"id_scenario": "12",
"id_commande": "4",
"ordre": "2",
"createdAt": null,
"updatedAt": null
},
{
"id": "23",
"id_scenario": "12",
"id_commande": "14",
"ordre": "3",
"createdAt": null,
"updatedAt": null
},
...
如您所见,这些对象按“ordre”参数排序,就像它:1、10、2、3,就像这个参数是一个字符串一样。
我尝试了很多组合,但没有一个奏效。 有人知道吗?
提前致谢!
克里斯托夫
最佳答案
我发现我的错误:我的数据库中的列“ordre”被设置为类型 varchar 而不是整数。
希望对大家有帮助!
再见
关于javascript - 对数字上的 sails 水线进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32480644/