2019-08-29 21:45:32 +08:00
|
|
|
const module = '../../../dist/jsoneditor'
|
2014-05-30 04:13:37 +08:00
|
|
|
require([module], function (JSONEditor) {
|
2013-11-16 01:11:50 +08:00
|
|
|
// create the editor
|
2019-08-29 21:45:32 +08:00
|
|
|
const container = document.getElementById('jsoneditor')
|
|
|
|
const editor = new JSONEditor(container)
|
2013-01-06 05:19:38 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
// set json
|
|
|
|
document.getElementById('setJSON').onclick = function () {
|
2019-08-29 21:45:32 +08:00
|
|
|
const json = {
|
2019-08-28 19:21:14 +08:00
|
|
|
array: [1, 2, 3],
|
|
|
|
boolean: true,
|
|
|
|
null: null,
|
|
|
|
number: 123,
|
|
|
|
object: { a: 'b', c: 'd' },
|
|
|
|
string: 'Hello World'
|
|
|
|
}
|
|
|
|
editor.set(json)
|
|
|
|
}
|
2013-01-06 05:19:38 +08:00
|
|
|
|
2013-11-16 01:11:50 +08:00
|
|
|
// get json
|
|
|
|
document.getElementById('getJSON').onclick = function () {
|
2019-08-29 21:45:32 +08:00
|
|
|
const json = editor.get()
|
2019-08-28 19:21:14 +08:00
|
|
|
window.alert(JSON.stringify(json, null, 2))
|
|
|
|
}
|
|
|
|
})
|