object.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <script src="../../dist/jsoneditor.js"></script>
  6. </head>
  7. <body>
  8. <textarea class="value" cols="30" rows="10"></textarea>
  9. <button class='get-value'>get value</button>
  10. <div class='container'></div>
  11. <script>
  12. var container = document.querySelector('.container');
  13. var value = document.querySelector('.value');
  14. var getValue = document.querySelector('.get-value');
  15. var schema = {
  16. "title": "Person",
  17. "type": "object",
  18. "required": [
  19. "zodiac"
  20. ],
  21. "properties": {
  22. "zodiac": {
  23. "title": "Zodiac",
  24. "type": "string",
  25. "minLength": 3
  26. },
  27. "values": {
  28. "title": "Values",
  29. "propertyOrder": 4,
  30. "type": "array",
  31. "uniqueItems": true,
  32. "items": {
  33. "type": "string",
  34. "enum": [
  35. "value A",
  36. "value B"
  37. ]
  38. }
  39. },
  40. "single": {
  41. "title": "Single",
  42. "propertyOrder": 3,
  43. "type": "boolean"
  44. },
  45. "name": {
  46. "title": "Name",
  47. "propertyOrder": 2,
  48. "type": "string",
  49. "default": "Francesco Avizzano"
  50. },
  51. "age": {
  52. "title": "Age",
  53. "propertyOrder": 1,
  54. "type": "number",
  55. "format": "number",
  56. "default": 10,
  57. "minimum": 18,
  58. "maximum": 80
  59. }
  60. }
  61. };
  62. var editor = new JSONEditor(container, {
  63. schema: schema,
  64. show_errors: 'always'
  65. });
  66. getValue.addEventListener('click', function () {
  67. value.value = JSON.stringify(editor.getValue());
  68. console.log(editor.getValue());
  69. });
  70. </script>
  71. </body>
  72. </html>