【问题标题】:Loopback: How to define a property with an array of strings in Loopback?Loopback:如何在 Loopback 中使用字符串数组定义属性?
【发布时间】:2017-07-10 19:45:44
【问题描述】:

我在环回应用程序中有以下模型,它将被持久化在 MongoDB 中:

型号

咖啡店名称:

  • 身份证
  • 名称(字符串)
  • 城市(字符串)

问题:

现在我希望能够将字符串列表存储在一个名为“tags”的新属性中:

  • 标签(字符串数组)

与其他必要的模型没有关系。我只需要一个简单的字符串列表。

我怎样才能做到这一点?

代码:

{
  "name": "CoffeeShop",
  "plural": "CoffeeShops",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    },
    "city": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

【问题讨论】:

    标签: loopbackjs loopback


    【解决方案1】:

    很简单:

    {
      "name": "CoffeeShop",
      "plural": "CoffeeShops",
      "base": "PersistedModel",
      "idInjection": true,
      "options": {
        "validateUpsert": true
      },
      "properties": {
        "name": {
          "type": "string",
          "required": true
        },
        "city": {
          "type": "string",
          "required": true
        },
        "tags": {
          "type": [
            "string"
          ],
          "required": false
        }
    },
      "validations": [],
      "relations": {},
      "acls": [],
      "methods": {}
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-14
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      • 2017-06-27
      • 2017-07-20
      • 1970-01-01
      相关资源
      最近更新 更多