【问题标题】:How to include and order an array using the Strongloop Loopback REST API?如何使用 Strongloop Loopback REST API 包含和排序数组?
【发布时间】:2016-08-28 23:38:45
【问题描述】:

通过添加条款,我在现有模型中包含了一个数组 {"include" : ["answers"]} 在名为用户/问题的模型中。因此,如果我得到用户/问题模型,我将得到一个答案列表。但是,现在我想根据 dateCreated 在我的问题模型中排序答案。为此,我应该如何编辑放置在 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,
  }
]

【问题讨论】:

    标签: android node.js rest loopbackjs strongloop


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多