12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Basic JSON Editor Example</title>
- <script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor/dist/jsoneditor.min.js"></script>
- </head>
- <body>
- <h1>Basic JSON Editor Example</h1>
-
- <div id='editor_holder'></div>
- <button id='submit'>Submit (console.log)</button>
-
- <script>
- // Initialize the editor with a JSON schema
- var editor = new JSONEditor(document.getElementById('editor_holder'),{
- schema: {
- type: "object",
- title: "Car",
- properties: {
- make: {
- type: "string",
- enum: [
- "Toyota",
- "BMW",
- "Honda",
- "Ford",
- "Chevy",
- "VW"
- ]
- },
- model: {
- type: "string"
- },
- year: {
- type: "integer",
- enum: [
- 1995,1996,1997,1998,1999,
- 2000,2001,2002,2003,2004,
- 2005,2006,2007,2008,2009,
- 2010,2011,2012,2013,2014
- ],
- default: 2008
- },
- safety: {
- type: "integer",
- format: "rating",
- maximum: "5",
- exclusiveMaximum: false,
- readonly: false
- }
- }
- }
- });
- // Hook up the submit button to log to the console
- document.getElementById('submit').addEventListener('click',function() {
- // Get the value from the editor
- console.log(editor.getValue());
- });
- </script>
- </body>
- </html>
|