android - 如何使用 Strongloop Loopback REST API 包含和排序数组?

标签 android node.js rest loopbackjs strongloop

我通过添加术语在现有模型中包含一个数组 {"include": ["answers"]} 在名为 User/Questions 的模型中。因此,如果我获得用户/问题模型,我将获得答案列表。但是,现在我想根据创建日期对问题模型中的答案进行排序。为此,我应该如何编辑放置在 REST Strongloop API 过滤器中的术语?

//QuestionModel

[
{
"question": "where is the coffee shop?"
"answers": [
 //answer model included
  {
    "answer": "I am not sure",
    "dateCreated": 4/1/16,
  },
 {
    "answer": "maybe try 5th avenue?",
    "dateCreated": 4/3/16,
  },
  {
    "answer": "oh its by the bakery",
    "dateCreated": 4/2/16,
  }
]

最佳答案

范围需要包含在当 querying related models 时。因此,对于您的示例,它将类似于:

 {"include": {"relation": "answers", "scope": {"order" : "dateCreated DESC"}}}

关于android - 如何使用 Strongloop Loopback REST API 包含和排序数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37012376/

相关文章:

android - 以钛为目标的其他平台是否只是 UI 更改的问题?

java - 以距离半径过滤位置 GeoPoint - Firestore

android - 通过热点在两个 Android 设备之间进行数据交换

android - 将android源代码作为eclipse中的项目导入

node.js - 错误: Most middleware (like cookieParser) is no longer bundled with Express and must be installed separately

rest - 线程 "main"java.lang.NoClassDefFoundError : com/sun/jersey/api/client/config/ClientConfig RestFul 中的异常

node.js - 使用 Node.js 创建 EC2 实例时关联弹性 IP

javascript - 使用nodejs在异步函数中使用await和async的语法是什么?

javascript - 如何在我的 React Native 应用程序中获得与 postman GET 中相同的内容?

rest - 具象状态传输 (REST) 和简单对象访问协议(protocol) (SOAP)