function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arun pattnaik 17Arun pattnaik 17 

how to get all the child components in controller js

i want to get all the list of child components in js controller.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Arun,

Greetings to you!

You can use aura:method or events. Please refer to the below links which might help you further with the above requirement.

https://sfdcpanther.wordpress.com/2018/01/05/call-child-component-controller-from-parent-component-aura-method/

https://sfdcpanther.wordpress.com/2017/12/03/play-with-events-in-lightning-component-part-1/

https://sfdcpanther.wordpress.com/2017/12/07/play-with-events-in-lightning-component-part-2/

https://sfdcpanther.wordpress.com/2017/12/25/play-with-events-in-lightning-component-part-3/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Arun pattnaik 17Arun pattnaik 17
Hello Anas,
ITs not regarging communicating with components. more over how to get the list of components inside a component in js.
Kranthi Kumar 118Kranthi Kumar 118
Hi Arun,

If you are using Iteration in creating child component you can make use of Events and List attribute to store the created compoonents.

Example:
Parent Component:

<aura:attribute name="childcomponents"  type="List"/>
<aura:handler name="cmpevent" event="c:cmpEvnt" action="{!c.addCmpToList}"
<aura:iteration>
      <c:childComponent />
</aura:iteration>

child Component :
<aura:registerEvent name="cmpEvent" type="c:cmpEvent"/>
<aura:handler name="init" value="{!this}" action="{!doinit}"/>
//Markup...

JS
doInit: function(cmp,event,helper){
//Get the Custome Event
//Assign the cmp to the event as parameter
//fire the Event 
}

Catch the fired event in parent controller addCmpToList Method  and  retrive the created component from event and  push into the List.

Kindly Let me know if it helps you to solve your query...

Thanks And Regards,
Kranthi