2013-05-04 17:34:02 +08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
2016-10-28 15:36:05 +08:00
|
|
|
<title>Switch mode | JSONEditor</title>
|
2015-05-15 03:29:35 +08:00
|
|
|
|
|
|
|
<!-- when using the mode "code", it's important to specify charset utf-8 -->
|
2013-11-16 01:11:50 +08:00
|
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
2013-05-04 17:34:02 +08:00
|
|
|
|
2015-03-01 03:47:23 +08:00
|
|
|
<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>
|
|
|
|
|
2016-10-28 19:31:13 +08:00
|
|
|
<h1>Switch mode</h1>
|
2013-05-04 17:34:02 +08:00
|
|
|
<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>
|
2016-10-14 23:30:16 +08:00
|
|
|
var container = document.getElementById('jsoneditor')
|
2013-05-04 17:34:02 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
var options = {
|
|
|
|
mode: 'tree',
|
2016-10-14 23:30:16 +08:00
|
|
|
modes: ['text', 'code', 'tree', 'form', 'view'], // allowed modes
|
2015-12-25 18:38:41 +08:00
|
|
|
onError: function (err) {
|
2016-10-14 23:30:16 +08:00
|
|
|
alert(err.toString())
|
2015-12-25 18:38:41 +08:00
|
|
|
},
|
2016-10-14 23:30:16 +08:00
|
|
|
onChangeMode: function (mode, prevMode) {
|
|
|
|
console.log('Mode switched from', prevMode, 'to', mode)
|
2013-11-16 01:11:50 +08:00
|
|
|
}
|
2016-10-14 23:30:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var editor = jsoneditor(container, options)
|
2013-08-28 04:50:20 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
var json = {
|
|
|
|
"array": [1, 2, 3],
|
|
|
|
"boolean": true,
|
|
|
|
"null": null,
|
|
|
|
"number": 123,
|
|
|
|
"object": {"a": "b", "c": "d"},
|
|
|
|
"string": "Hello World"
|
2016-10-14 23:30:16 +08:00
|
|
|
}
|
2013-08-28 04:50:20 +08:00
|
|
|
|
2016-10-14 23:30:16 +08:00
|
|
|
editor.set(json)
|
2013-05-04 17:34:02 +08:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|