-
Notifications
You must be signed in to change notification settings - Fork 114
/
basic_usage.html
56 lines (49 loc) · 1.28 KB
/
basic_usage.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JSONEditor | Basic usage</title>
<style>
#jsoneditor {
width: 600px;
height: 500px;
}
</style>
</head>
<body>
<p>
<button id="setContent">Set content</button>
<button id="getContent">Get content</button>
</p>
<div id="jsoneditor"></div>
<script type="module">
import { createJSONEditor } from '../../package-vanilla/standalone.js'
// create the editor
const editor = createJSONEditor({
target: document.getElementById('jsoneditor')
})
// set json
document.getElementById('setContent').onclick = function () {
const content = {
text: undefined, // used in text mode
json: {
array: [1, 2, 3],
boolean: true,
color: '#82b92c',
null: null,
number: 123,
object: { a: 'b', c: 'd' },
time: 1575599819000,
string: 'Hello World'
}
}
editor.set(content)
}
// get json
document.getElementById('getContent').onclick = function () {
const content = editor.get()
alert(JSON.stringify(content, null, 2))
}
</script>
</body>
</html>