2013-08-28 04:50:20 +08:00
|
|
|
var module = '../../../jsoneditor';
|
2013-01-06 05:19:38 +08:00
|
|
|
require([module], function (jsoneditor) {
|
|
|
|
// create the editor
|
2013-08-28 04:50:20 +08:00
|
|
|
var container = document.getElementById('jsoneditor');
|
2013-01-06 05:19:38 +08:00
|
|
|
var editor = new jsoneditor.JSONEditor(container);
|
|
|
|
|
|
|
|
// set json
|
2013-08-28 04:50:20 +08:00
|
|
|
document.getElementById('setJSON').onclick = function () {
|
2013-01-06 05:19:38 +08:00
|
|
|
var json = {
|
2013-08-28 04:50:20 +08:00
|
|
|
'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
|
|
|
};
|
|
|
|
editor.set(json);
|
|
|
|
};
|
|
|
|
|
|
|
|
// get json
|
2013-08-28 04:50:20 +08:00
|
|
|
document.getElementById('getJSON').onclick = function () {
|
2013-01-06 05:19:38 +08:00
|
|
|
var json = editor.get();
|
|
|
|
alert(JSON.stringify(json, null, 2));
|
|
|
|
};
|
|
|
|
});
|