2020-05-07 02:11:59 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset='utf-8'>
|
|
|
|
|
|
|
|
<title>JSONEditor | Basic usage</title>
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
#jsoneditor {
|
|
|
|
width: 500px;
|
|
|
|
height: 500px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p>
|
|
|
|
<button id="setJSON">Set JSON</button>
|
|
|
|
<button id="getJSON">Get JSON</button>
|
|
|
|
</p>
|
|
|
|
<div id="jsoneditor"></div>
|
|
|
|
|
|
|
|
<script type="module">
|
2020-05-07 02:22:49 +08:00
|
|
|
import jsoneditor from '../dist/es/jsoneditor.js'
|
2020-05-07 02:11:59 +08:00
|
|
|
|
|
|
|
// create the editor
|
|
|
|
const editor = jsoneditor({
|
|
|
|
target: document.getElementById('jsoneditor')
|
|
|
|
})
|
|
|
|
|
|
|
|
// set json
|
|
|
|
document.getElementById('setJSON').onclick = function () {
|
|
|
|
const 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(json)
|
|
|
|
}
|
|
|
|
|
|
|
|
// get json
|
|
|
|
document.getElementById('getJSON').onclick = function () {
|
|
|
|
const json = editor.get()
|
|
|
|
alert(JSON.stringify(json, null, 2))
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|