GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.36k stars 4.05k forks source link

[Bug] getComponents method doesn't return tree of components #2664

Closed Podvodila closed 4 years ago

Podvodila commented 4 years ago

I'm trying to implement multiple pages as per discussion in that issue - https://github.com/artf/grapesjs/issues/1331 But when I trying to get components tree by using 'editor.getComponents()' it returns data with wrong format(model collection I guess). When I try to set components using the editor.SetComponents method nothing happens (in my project, but on JSFiddle I get an error in the console).

I want to get the components of the editor in the same format in which the StorageManager sends them in the gjs-components parameter to the server when saving. Could somebody tell me what am I doing wrong?

JSFiddle issue reproduction demo - https://jsfiddle.net/0epyuqk3/

Podvodila commented 4 years ago

Need to stringify and parse back returned components(works only if components were set programmatically initially) JSON.parse(JSON.stringify(editor.getComponents())) https://jsfiddle.net/w1497xp8/

Upd.: same with editor.getStyles() method

artf commented 4 years ago

Yes, this is the correct way to obtain the same string of the StorageManager