0

I'm trying to generate a form which will have multiple vehicles and each vehicle should have multiple people inside it.

I tried to do it by using an array inside another array. But for some obscure reasons it's not working.

This is what I want: http://i.imgur.com/ZB2kCa1.png

This is what I have (so far):

Form:

[
  {
    "key": "vehicles",
    "items": [
      "['vehicles'][]['plate-number']",
      "['vehicles'][]['color']",
      {
        "key": "people",
        "items": [
            "['vehicles'][]['people'][]['name']"
        ]
      }
    ]
  }
]

Schema:

{
  "type": "object",
  "properties": {
    "vehicles": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "plate-number": {
            "title": "Plate number",
            "type": "string"
          },
          "color": {
            "title": "Color",
            "type": "string"
          },
          "people": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string",
                  "enum": ["dr","jr","sir","mrs","mr","NaN","dj"]
                },
                "name": {
                  "title": "Name",
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}

Edit: stefankmitph's answer solvers my problem. Thank you!

But something weird is happening: a new object person is added at the same level of vehicles. Also, when I fill a person's information and then delete this person the models is not updated.

4

1 回答 1

1

您提供的架构不添加属性“性别”(如您的图片链接所示)。所以我选择了“title”而不是“gender”:

[
  {
    "key": "vehicles",
    "items": [
      "vehicles[].plate-number",
      "vehicles[].color", {
          "key": "people",
          "type": "array",
          "title": "People",
          "items": [
              "vehicles[].people[].name",
              "vehicles[].people[].title"
              ]
      }
    ]
  }
]

我希望这就是你要找的!注意:使用模式表单示例页面测试

于 2015-04-05T17:03:17.067 回答