Issue #1966Opened April 19, 2019by trafalmejo0 reactions

[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)

artfApril 23, 20190 reactions

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
})
trafalmejoApril 24, 20190 reactions

Perfect! Highly appreciated.

lock[bot]April 25, 20200 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.