2014-07-19 2 views
2

자바 스크립트 플러그인 JSON Editor을 사용하려고 며칠 동안 고생했습니다. SWIG JS engine을 사용하고 있지만 문제를 해결할 수있는 제안이 열려 있습니다.JSON 스키마 템플릿 및 JSON 편집기

지금까지 제대로 작동하는 JSON 템플릿을 만들었지 만 그렇게해야 할 필요가 완전히 없으며 JSON 편집기 github 페이지에서 제공하는 구문을 이해하고 사용하려고 시도했지만 지금까지는 행운이 없습니다.

features.type == "포인트"나는이 유형의 속성을 가지고 features.display 원하는 값 "#/정의/마커 경우 :

어떻게 다음과 같은 템플릿 동작합니다을 만들 수 있습니다 ". 그렇지 않으면 (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" ] 
     } 
    } 
} 

답변

1

(jsonschema 초안 5 appareance까지)이 시행하는 유일한 방법은 판별으로 열거를 사용하는 것입니다. 예를 찾을 수 있습니다. How to use dependencies in JSON schema (draft-04)

+0

감사합니다. 필자는 여러 파일에 대한 참조를 사용하여 두 개의 분기 계층 구조를 만들고 플러그인 초기화시 올바른 아키텍처를 선택하여 작업을 마쳤습니다. 초안 5를 기다리는 것이 훨씬 쉽습니다. – user3856210