yakovlevga / brickyeditor

WYSIWYG block editor jQuery plugin.
MIT License
115 stars 20 forks source link

[Question] about saving JSON #1

Closed oleteacher closed 7 years ago

oleteacher commented 7 years ago

Great project! Really like how clean and fast things are with brickyeditor.

"Since BrickyEditor can save blocks as JSON"

Could you explain or maybe show example how edited content is saved to JSON file(s)? I do not understand how to save the content of a modified page to a JSON file.

Thanks for sharing your project.

Susan

yakovlevga commented 7 years ago

Hi! You can use editor.getData() function, to retrive array of blocks, then just stringify it to JSON. There is sample in demo page http://brickyeditor.info/examples.html (select JSON representation on top left corner).

$("#editor").brickyeditor({
    onload: function(editor) {
        $("#getJson").on("click", function() {
            var data = editor.getData(); // this is array of blocks
            var json = JSON.stringify(data, null, "\t"); // just stringify it to JSON
        });
    }
});

Sorry for poor README at this moment, I'll try to fill it in nearest time.

oleteacher commented 7 years ago

Thank you for info George. I will try to get my brain in gear and figure this out. Sure it is simple but not grasping today:)

No need to apologize about readme.

Thanks again.

Susan