forked from josdejong/jsoneditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16_synchronize_editors.html
66 lines (57 loc) · 1.45 KB
/
16_synchronize_editors.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
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSONEditor | Synchronize two editors</title>
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
<script src="../dist/jsoneditor.js"></script>
<style type="text/css">
body {
font-family: sans-serif;
}
#jsoneditor1,
#jsoneditor2 {
width: 500px;
height: 500px;
margin-right: 10px;
display: inline-block;
}
</style>
</head>
<body>
<p>
Keep two editors synchronized using <code>onChangeText</code> and <code>updateText</code>.
</p>
<p>
This can be done too with <code>onChangeJSON</code> and <code>update</code>, which can only be used in
modes <code>tree</code>, <code>form</code> (and <code>view</code>).
</p>
<div id="jsoneditor1"></div>
<div id="jsoneditor2"></div>
<script>
// create editor 1
const editor1 = new JSONEditor(document.getElementById('jsoneditor1'), {
onChangeText: function (jsonString) {
editor2.updateText(jsonString)
}
})
// create editor 2
const editor2 = new JSONEditor(document.getElementById('jsoneditor2'), {
onChangeText: function (jsonString) {
editor1.updateText(jsonString)
}
})
// set initial data in both editors
const json = {
'array': [1, 2, 3],
'boolean': true,
'null': null,
'number': 123,
'object': {'a': 'b', 'c': 'd'},
'string': 'Hello World'
}
editor1.set(json)
editor2.set(json)
</script>
</body>
</html>