jsoneditor/examples/09_synchronize_two_editors....

65 lines
1.3 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<head>
2016-11-12 03:26:32 +08:00
<meta charset="UTF-8">
<title>Synchronize two editors | JSONEditor</title>
<script src="../dist/jsoneditor.js"></script>
<style type="text/css">
body {
font-family: arial, sans-serif;
}
#jsoneditor1,
#jsoneditor2 {
display: inline-block;
width: 350px;
height: 500px;
margin-right: 24px;
}
2016-12-26 17:41:07 +08:00
code {
background: #e5e5e5;
}
</style>
</head>
<body>
2016-10-28 19:31:13 +08:00
<h1>Synchronize two editors</h1>
<p>
This example demonstrates how to keep two editors synchronized by listening for
2016-12-26 17:41:07 +08:00
the <code>onPatch</code> event. Other related events are <code>onChange</code> and <code>onChangeText</code>.
</p>
<div id="jsoneditor1"></div>
<div id="jsoneditor2"></div>
<script>
var json = {
'array': [1, 2, 3],
'boolean': true,
'null': null,
'number': 123,
'object': {'a': 'b', 'c': 'd'},
'string': 'Hello World'
}
var editor1 = jsoneditor(document.getElementById('jsoneditor1'), {
2016-12-26 17:41:07 +08:00
onPatch: function (patch, revert) {
editor2.patch(patch)
}
})
editor1.set(json)
var editor2 = jsoneditor(document.getElementById('jsoneditor2'), {
2016-12-26 17:41:07 +08:00
onPatch: function (patch, revert) {
editor1.patch(patch)
}
})
editor2.set(json)
</script>
</body>
</html>