Issue #2664Opened March 18, 2020by Podvodila2 reactions

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

Question

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/

Answers (2)

PodvodilaMarch 18, 20202 reactions

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

artfMarch 19, 20200 reactions

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

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.