【问题标题】:Loading a select box options on the basis of other select box using jsonSchema使用 jsonSchema 在其他选择框的基础上加载选择框选项
【发布时间】:2016-01-29 07:09:18
【问题描述】:

我正在使用 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 尝试过,但没有成功。另外,我尝试使用watchenumSource 来完成此操作,如here 所述

任何帮助都是值得的。

谢谢!

【问题讨论】:

    标签: json jsonschema json-schema-validator


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-02-28
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多