2015-03-01 03:47:23 +08:00
|
|
|
var module = '../../../dist/jsoneditor';
|
2016-08-14 03:38:32 +08:00
|
|
|
require([module], function (jsoneditor) {
|
2013-11-16 01:11:50 +08:00
|
|
|
// create the editor
|
|
|
|
var container = document.getElementById('jsoneditor');
|
2016-08-14 03:38:32 +08:00
|
|
|
var editor = 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 () {
|
|
|
|
var json = {
|
|
|
|
'array': [1, 2, 3],
|
|
|
|
'boolean': true,
|
|
|
|
'null': null,
|
|
|
|
'number': 123,
|
|
|
|
'object': {'a': 'b', 'c': 'd'},
|
|
|
|
'string': 'Hello World'
|
2013-01-06 05:19:38 +08:00
|
|
|
};
|
2013-11-16 01:11:50 +08:00
|
|
|
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 () {
|
|
|
|
var json = editor.get();
|
|
|
|
alert(JSON.stringify(json, null, 2));
|
|
|
|
};
|
2013-01-06 05:19:38 +08:00
|
|
|
});
|