LoopBack 3.0:过滤器不返回REST API的结果

时间:2017-11-05 20:13:26

标签: rest loopbackjs

我有一个LoopBack API,其中包含一个简单的模型:

{
  "name": "Establishment",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "Distance": {
      "type": "number"
    },
    "EstablishmentId": {
      "type": "number"
    },
    "EstablishmentType": {
      "type": "string"
    },
    "Location": {
      "type": "string"
    },
    "MinCost": {
      "type": "number"
    },
    "Name": {
      "type": "string"
    },
    "Stars": {
      "type": "number"
    },
    "UserRating": {
      "type": "number"
    },
    "UserRatingTitle": {
      "type": "string"
    },
    "UserRatingCount": {
      "type": "number"
    },
    "ImageUrl": {
      "type": "string"
    },
    "ThumbnailUrl": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

http://localhost:3000/api/Establishments的简单调用会返回所有结果,如预期的那样;但是对http://localhost:3000/api/Establishments?filter[where][distance][gt]=30的调用根本不会产生任何结果:空数组。

有很多EstablishmentDistance大于30;实际上在其他属性上使用where过滤器也会产生一个空数组。我能错过什么?

1 个答案:

答案 0 :(得分:0)

正如我在评论中提到的,它区分大小写,我在应用程序上对其进行了修改以确定它。

它应该是:

http://localhost:3000/api/Establishments?filter[where][Distance][gt]=30

或者您可以尝试使用以下格式:

http://localhost:3000/api/Establishments?filter={"where":{"Distance":{"gt":30}}}