2013-05-04 17:34:02 +08:00
|
|
|
<!DOCTYPE HTML>
|
2020-09-23 16:23:38 +08:00
|
|
|
<html lang="en">
|
2013-05-04 17:34:02 +08:00
|
|
|
<head>
|
2015-05-15 03:29:35 +08:00
|
|
|
<!-- when using the mode "code", it's important to specify charset utf-8 -->
|
2020-09-23 16:23:38 +08:00
|
|
|
<meta charset="utf-8">
|
|
|
|
|
|
|
|
<title>JSONEditor | Switch mode</title>
|
2013-05-04 17:34:02 +08:00
|
|
|
|
2015-03-01 03:47:23 +08:00
|
|
|
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
|
|
|
|
<script src="../dist/jsoneditor.js"></script>
|
2013-05-04 17:34:02 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
<style type="text/css">
|
|
|
|
body {
|
|
|
|
font: 10.5pt arial;
|
|
|
|
color: #4d4d4d;
|
|
|
|
line-height: 150%;
|
|
|
|
width: 500px;
|
|
|
|
}
|
2013-05-04 17:34:02 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
code {
|
|
|
|
background-color: #f5f5f5;
|
|
|
|
}
|
2013-08-28 04:50:20 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
#jsoneditor {
|
|
|
|
width: 500px;
|
|
|
|
height: 500px;
|
|
|
|
}
|
|
|
|
</style>
|
2013-05-04 17:34:02 +08:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<p>
|
2013-11-16 01:11:50 +08:00
|
|
|
Switch editor mode using the mode box.
|
|
|
|
Note that the mode can be changed programmatically as well using the method
|
|
|
|
<code>editor.setMode(mode)</code>, try it in the console of your browser.
|
2013-05-04 17:34:02 +08:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<div id="jsoneditor"></div>
|
|
|
|
|
2015-02-28 04:54:04 +08:00
|
|
|
<script>
|
2019-08-29 21:45:32 +08:00
|
|
|
const container = document.getElementById('jsoneditor')
|
2013-05-04 17:34:02 +08:00
|
|
|
|
2019-08-29 21:45:32 +08:00
|
|
|
const options = {
|
2013-11-16 01:11:50 +08:00
|
|
|
mode: 'tree',
|
2019-07-09 02:00:34 +08:00
|
|
|
modes: ['code', 'form', 'text', 'tree', 'view', 'preview'], // allowed modes
|
2015-12-25 18:38:41 +08:00
|
|
|
onError: function (err) {
|
2019-08-29 21:45:32 +08:00
|
|
|
alert(err.toString())
|
2015-12-25 18:38:41 +08:00
|
|
|
},
|
|
|
|
onModeChange: function (newMode, oldMode) {
|
2019-08-29 21:45:32 +08:00
|
|
|
console.log('Mode switched from', oldMode, 'to', newMode)
|
2013-11-16 01:11:50 +08:00
|
|
|
}
|
2019-08-29 21:45:32 +08:00
|
|
|
}
|
2013-08-28 04:50:20 +08:00
|
|
|
|
2019-08-29 21:45:32 +08:00
|
|
|
const json = {
|
2013-11-16 01:11:50 +08:00
|
|
|
"array": [1, 2, 3],
|
|
|
|
"boolean": true,
|
|
|
|
"null": null,
|
|
|
|
"number": 123,
|
|
|
|
"object": {"a": "b", "c": "d"},
|
|
|
|
"string": "Hello World"
|
2019-08-29 21:45:32 +08:00
|
|
|
}
|
2013-08-28 04:50:20 +08:00
|
|
|
|
2019-08-29 21:45:32 +08:00
|
|
|
const editor = new JSONEditor(container, options, json)
|
2013-05-04 17:34:02 +08:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|