更改环回中检索的默认顺序
Change the default order of retrieval in loopback
我有一个环回 api 可以检索一些对象。这些对象有一个 属性 createdAt
。我想根据此 属性 更改 api 检索的对象的顺序。实现这一目标的最佳方法是什么?
您可以通过多种方式使用顺序过滤器,在您的 :
休息 API :
这是一个 属性,您可以选择 ASC 或 DESC :
filter[order]=createdAt <ASC|DESC>
这是不止一个 属性 :
filter[order][0]=createdAt <ASC|DESC>&filter[order][1][updatedAt]=<ASC|DESC>...
节点API
model.find({
order: 'createdAt DESC',
});
HERE the official documentation of the explanation above.
模型定义JSON
您可以在 JSON 模型文件中使用范围 属性,我推荐它。
"scope": {
"order": "createdAt ASC",
"where": {
"field": "something" // you can use the where filter also ...
}
},
Check this official documentation for more information about SCOPES
我有一个环回 api 可以检索一些对象。这些对象有一个 属性 createdAt
。我想根据此 属性 更改 api 检索的对象的顺序。实现这一目标的最佳方法是什么?
您可以通过多种方式使用顺序过滤器,在您的 :
休息 API :
这是一个 属性,您可以选择 ASC 或 DESC :
filter[order]=createdAt <ASC|DESC>
这是不止一个 属性 :
filter[order][0]=createdAt <ASC|DESC>&filter[order][1][updatedAt]=<ASC|DESC>...
节点API
model.find({
order: 'createdAt DESC',
});
HERE the official documentation of the explanation above.
模型定义JSON
您可以在 JSON 模型文件中使用范围 属性,我推荐它。
"scope": {
"order": "createdAt ASC",
"where": {
"field": "something" // you can use the where filter also ...
}
},
Check this official documentation for more information about SCOPES