3

JSON Editor Javascript プラグインを使用しようとして、数日間苦労しています。私はSWIG JS エンジンを使用していますが、私の問題を解決する提案を受け付けています。

これまでのところ問題なく動作する JSON テンプレートを作成しましたが、必要なことを完全には達成できませんでした。JSON エディター github ページで提供されている構文を理解し、使用しようとしましたが、今のところうまくいきません。

テンプレートを次のように動作させるにはどうすればよいですか:

features.type == "Point" の値の場合、features.display に "#/definitions/marker" タイプのプロパティを持たせます。それ以外の場合 (features.type == "Polygon") features.display に "#/definitions/area" タイプのプロパティを持たせたい。同じことが filter.display にも当てはまります。

これまでのところ、私は「oneOf」プロパティを使用しています。これは、私が望むものに最も近いためですが、完全ではないことは間違いありません。

ご協力いただきありがとうございます !

敬具。

これまでのJSONスキーマは次のとおりです。

{
    "type": "array",
    "title": "Layers",
    "items": {
        "title": "Layer",
        "type": "object",
        "headerTemplate": "{{table.id.public_name}}",
        "properties": {
            "table":{"$ref": "#/definitions/table"},
            "features":{"$ref": "#/definitions/features"}
        }
    },
    "definitions": {
        "table": {
            "title": "Table Information",
            "type": "object",
            "properties": {
                "id":{"$ref": "#/definitions/id"},
                "primary_key":{"$ref": "#/definitions/primary_key"},
                "read":{"$ref": "#/definitions/read"}
            }
        },
        "features": {
            "title": "Features Settings",
            "type": "object",
            "properties": {
                "type":{"$ref": "#/definitions/type"},
                "id":{"$ref": "#/definitions/id"},
                "cols":{"$ref": "#/definitions/cols"},
                "display": {
                    "type": "object",
                    "title": "Display",
                    "format": "grid",
                    "oneOf": [
                        {"$ref": "#/definitions/marker"},
                        {"$ref": "#/definitions/area"}
                    ]
                }
            }
        },
        "cols": {
            "title": "Table Columns",
            "type": "array",
            "items": {
                "type": "object",
                "title": "Column",
                "properties": {
                    "id":{"$ref": "#/definitions/id"},
                    "read":{"$ref": "#/definitions/read"},
                    "write":{"$ref": "#/definitions/write"},
                    "filter":{"$ref": "#/definitions/filter"}
                }
            }
        },
        "id": {
            "title": "Identifier",
            "type": "object",
            "format": "grid",
            "properties": {
                "name":{"$ref": "#/definitions/name"},
                "public_name":{"$ref": "#/definitions/public_name"}
            }
        },
        "name": {
            "title": "Name",
            "type": "string"
        },
        "public_name": {
            "title": "Public Name",
            "type": "string"
        },
        "primary_key": {
            "title": "Primary key",
            "type": "string",
            "format": "grid"
        },
        "write": {
            "title": "Editing",
            "type": "object",
            "format": "grid",
            "properties": {
                "read":{"$ref": "#/definitions/read"},
                "method":{"$ref": "#/definitions/method"}
            }
        },
        "read": {
            "title": "Reading",
            "type": "array",
            "items": {
                "type": "integer",
                "title": "Access Level",
                "format": "grid",
                "properties":{"$ref": "#/definitions/access_level"}
            }
        },
        "type": {
            "title": "Type",
            "type": "string",
            "enum": [ "Point", "Polygon" ]
        },
        "access_level": {
            "title": "Access Level",
            "type": "integer",
            "format": "number"
        },
        "method": {
            "title": "Method",
            "type": "object",
            "format": "grid",
            "properties": {
                "type":{"$ref": "#/definitions/method_type"},
                "data":{"$ref": "#/definitions/data"}
            }
        },
        "data": {
            "title": "Data",
            "type": "array",
            "items": {
                "type": "string",
                "title": "Data",
                "format": "grid",
                "properties":{"$ref": "#/definitions/value"}
            }
        },
        "value": {
            "title": "Value",
            "type": "string"
        },
        "filter": {
            "title": "Filter",
            "type": "array",
            "items": {
                "type": "object",
                "title": "Filter",
                "properties": {
                    "value":{"$ref": "#/definitions/value"},
                    "display": {
                        "type": "object",
                        "oneOf": [
                            {"$ref": "#/definitions/marker"},
                            {"$ref": "#/definitions/area"}
                        ]
                    }
                }
            }
        },
        "marker": {
            "title": "Marker",
            "type": "object",
            "format": "grid",
            "properties": {
                "color":{"$ref": "#/definitions/color"},
                "icon":{"$ref": "#/definitions/icon"}
            }
        },
        "color": {
            "title": "Color",
            "type": "string",
            "enum": ["red", "darkred", "orange", "green", "darkgreen", "blue", "purple", "darkpuple", "cadetblue"]
        },
        "css_color": {
            "title": "CSS Color",
            "type": "string",
            "format": "color"
        },
        "icon": {
            "title": "Icon",
            "type": "object",
            "format": "grid",
            "properties": {
                "name":{"$ref": "#/definitions/name"},
                "color":{"$ref": "#/definitions/css_color"}
            }
        },
        "area": {
            "title": "Area",
            "type": "object",
            "properties": {
                "color":{"$ref": "#/definitions/color"},
                "border":{"$ref": "#/definitions/border"}
            }
        },
        "border": {
            "title": "Border",
            "type": "object",
            "properties": {
                "border_color":{"$ref": "#/definitions/border_color"},
                "width":{"$ref": "#/definitions/width"}
            }
        },
        "border_color": {
            "title": "Color",
            "type": "object",
            "format": "grid",
            "properties": {
                "normal":{"$ref": "#/definitions/normal"},
                "hover":{"$ref": "#/definitions/hover"}
            }
        },
        "width": {
            "title": "Width",
            "type": "string"
        },
        "normal": {
            "title": "Normal",
            "type": "string",
            "format": "color"
        },
        "hover": {
            "title": "Hover",
            "type": "string",
            "format": "color"
        },
        "method_type": {
            "title": "Type",
            "type": "string",
            "enum": [ "text", "select" ]
        }
    }
}
4

1 に答える 1

2

これを強制する唯一の方法 (jsonschema ドラフト 5 が登場するまで) は、enum を識別子として使用することです。JSON スキーマで依存関係を使用する方法 (draft-04) で例を見つけることができます。

于 2014-08-20T06:38:32.210 に答える