Issue #789Opened January 23, 2018by Geczy1 reactions

getComponents doesn't return components

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, 20181 reactions

@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, 20180 reactions

Works great, thanks

lock[bot]September 18, 20190 reactions

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.