Issue #789💬 AnsweredOpened January 23, 2018by Geczy1 reactions

GetComponents doesn't return components

快速解答by artf1

@Geczy probably I've to update the description, but getComponents just returns wrapper's components (with its children), if you want to return an array of all components you can do this:

Read full answer below ↓

Question

It's as if it's not parsing down the DOM

Reproduce. View console log https://codesandbox.io/s/lxl7x2mnq

image You can see there are way more than 5 components / models in this sandbox.

But console log only shows 5 image

If I add one to the root of the dom tree, it will show 6. But if I add one to a child component, it will not see it.

Try dragging Link or any other component around in several places until you see the issue

Answers (3)

artfJanuary 24, 2018

@Geczy probably I've to update the description, but getComponents just returns wrapper's components (with its children), if you want to return an array of all components you can do this:

const getAllComponents = (model, result = []) => {
	result.push(model);
	model.components().each(mod => getAllComponents(mod, result))
	return result;
}
const all = getAllComponents(editor.DomComponents.getWrapper());
GeczyJanuary 24, 2018

Works great, thanks

lock[bot]September 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.