[QUESTION] Loop over all components
Question
Hi all,
I want to create a socket for every button that I add to the canvas. This is working just fine. However, when I reload (using storage), I have to look for my components of type "Button" and reopen the sockets. Is it a way to loop over the components?
Best,
Answers (3)
Hi @trafalmejo in case you need to iterate component's first level children you can do this:
yourComponent.components().forEach(component => {
if (component.is('COMPONENT-ID')) {
// do something
}
})
If you need to lookup ALL inner children, use onAll
yourComponent.onAll(component => {
if (component.is('COMPONENT-ID')) {
// do something
}
})
Once the component is rendered you can also make use of find method and pass any query selector string
yourComponent.find(`[data-gjs-type=COMPONENT-ID]`).forEach(component => {
// do something
})
Perfect! Highly appreciated.
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.
Issue #1731
[QUESTION] What is the best way to manage dynamic components?
Hi, can you please tell me what is the best way to manage dynamic templates. I want to describe you what's my case.Have e-commerce store an...
Issue #1964
[QUESTION] Minimal requirements to create a custom component
I've been reading the docs all day on creating a custom component. I've also looked at grapesjs-mjml for an example. I'm trying to create a...
Issue #1580
[Question] Add Custom Button to RTE
Hello all, i'm currently trying to move away from ckeditor (used in an legacy app to create emails and microsites). This works very well ac...
Issue #1875
[QUESTION] ID changes when importing html or passing html in components prop in config.
Hi, I built a component and block that I can drag and drop in the canvas. My issue is that some styles rely on the ID. I know this might no...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.