1

我正在为我的应用程序尝试 Angular6 JSON 表单,但遇到了数组模式的问题

基本布局看起来像

{
  "schema": {
        "type": "array",
        "properties": {
            "type": { "type": "string" },
            "number": { "type": "string" },
        }
  },
  "layout": [
    { 
      "type": "array",
      "items": [ {
        "type": "div",
        "displayFlex": true,
        "flex-direction": "row",
        "items": [
          { "key": "type", "flex": "1 1 50px",
            "notitle": true, "placeholder": "Type"
          },
          { "key": "number", "flex": "4 4 200px",
            "notitle": true, "placeholder": "Phone Number"
          }
        ]
      } ]
    }
  ],
  "data": [
      { "type": "cell", "number": "702-123-4567" },
      { "type": "work", "number": "702-987-6543" }
    ]
}

但我没有得到预期的结果,即表格预先填充了数据

[
          { "type": "cell", "number": "702-123-4567" },
          { "type": "work", "number": "702-987-6543" }
        ]

参考:https ://hamidihamza.com/Angular6-json-schema-form/

在此处输入图像描述

4

1 回答 1

0

根据您的代码,您可能需要重新访问某些部分。

  • 架构类型应该是基于文档http://json-schema.org/latest/json-schema-core.html的对象或布尔值
  • 在 schema 部分中,您似乎希望 type 和 number 成为 JSON 实例的属性。有了这个,您只能将一个数据实例传递给框架来填写您的属性,因为框架无法决定为您的字符串类型的属性使用哪个值。
  • 如果要查找具有类型和数字的数组,则可以使用类型数组具有类似“电话号码”的属性。下面是来自 angular6-json-schema flex 布局示例的示例,我认为您可以参考。
"schema": {
 ...
   "phone_numbers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "type": { "type": "string", "enum": [ "cell", "home", "work" ] },
          "number": { "type": "string" }
        },
        "required": [ "type", "number" ]
}

并传递您的数据,如下所示:

"data": {
...
"phone_numbers": [
      { "type": "cell", "number": "702-123-4567" },
      { "type": "work", "number": "702-987-6543" }
    ],
}
于 2019-08-20T20:12:39.627 回答