首页 > 解决方案 > LoopBackJs REST API 创建响应不返回完整模型,只返回表单数据

问题描述

当我使用仅包含必填字段的对象发布到 api/testmodel 时,该对象正在数据库中正确创建。但是,我只得到我在请求正文中发送的对象。我正在尝试获取响应中包含空字段的完整对象。

谢谢您的帮助!

{
  "name": "test",
  "plural": "test",
  "base": "PersistedModel",
  "idInjection": true,
  "replaceOnPUT": false,
  "properties": {
    "city": {
      "type": "string",
      "length": 100
    },
    "name": {
      "type": "string",
      "required": true,
      "length": 100
    },
    "id": {
      "type": "string",
      "id": true,
      "required": true,
    },
    "officePhone": {
      "type": "string",
      "length": 100
    },
    "status": {
      "type": "string",
      "required": false,
      "length": 200
    },
    "street": {
      "type": "string",
      "length": 100
    }
  },
 "methods": {}`

标签: loopbackjs

解决方案


然后你需要为你的模型创建默认值,例如城市:

"properties": {
    "city": {
      "type": "string",
      "length": 100,
      "default": ""

    },
...

推荐阅读