1

我正在使用 jsonschema 来生成我们的表单并验证这些。

下面是一个示例 json:

{
  "title": "Microsoft Account Request",
  "readOnly": false,
  "$schema": "http://json-schema.org/draft-04/hyper-schema",
  "description": "Microsoft Azure Account Request Product Specification",
  "properties": {
    "product": {
      "title": "Product",
      "dataBinding": {"references": ["SPEC_ID#/properties/service"]},
      "properties": {
        "offers": {
          "title": "Product Offers",
          "propertyOrder": 1,
          "type": "array",
          "uniqueItems": true,
          "format": "tabs",
          "items": {
            "title":"Product Offer",
            "properties": {
              "category": {
                "title": "Category",
                "readOnly": false,
                "unique":true,
                "strictProperties": true,
                "enum": [
                  "Cloud Services",
                  "Virtual Machines",
                  "Azure App Service",
                  "Batch"


                ],
                "options": {
                    "dependencies": [
                      {"id":"subcategoryAdd", "value":true}
                    ]
                  },
                "description": "Select category",
                "propertyOrder": 1,
                "type": "string"
              },
              "subcategory": {
                  "id":"subcategoryAdd",
                "title": "Sub - Category",
                "readOnly": false,
                "strictProperties": true,
                "description": "Select Sub-Category",
                 "options": {
                    "hide_display": true
                  },
                "enum": [
                  "Build and Deployment",
                  "Application Insights"
                ],
                "propertyOrder": 2,
                "type": "string"
              }
            },
            "type": "object"
          }
        }

      },
      "type": "object"
    }
  },
  "type": "object"
}

和样本输出:

在此处输入图像描述

在输出表单中,我在其选择框中突出显示了子类别选项,应根据所选类别加载。

例如,如果我选择batch子类别选项 a、b、c 应显示在子类别的选择框中,如果我选择Azure app service子类别选项 d、e、f 应显示在子类别的选择框中。

我正在尝试dependencies但徒劳无功。另外,我尝试通过使用watch和来完成此操作,如此enumSource所述

任何帮助都是值得的。

谢谢!

4

1 回答 1

1

您的类别/子类别关系可以使用以下 JSON 模式进行验证。

{
  "type": "object",
  "anyOf": [
    {
      "properties": {
        "category": { "enum": ["foo"] },
        "subCategory": { "enum": ["asdf", "jkl;"] }
      }
    },
    {
      "properties": {
        "category": { "enum": ["bar"] },
        "subCategory": { "enum": ["asdf", "qwer", "uiop"] }
      }
    }
  ]
}

但是,这并不意味着您使用的表单生成器将能够基于此创建表单。如果可以的话,我会很感动。

于 2016-01-30T01:01:23.673 回答