You need to sign in to do that
Don't have an account?
Aleksey Sheldagaev
Get child component by aura:id using find() method
Can sombody explain why I get 'null' in my component's controller when trying to find child component by aura:id within aura:iteration
Here are markup and controller code example:
Here are markup and controller code example:
<aura:component> <aura:attribute name="someObjs" type="Object[]" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <div class="wrapper"> <ui:button label="Click me" press="{!c.changeObjectTxt}" /> <aura:iteration items="{!v.someObjs}" var="obj"> <c:SimpleChildComponent someText="{!obj.txt}" aura:id="item_{!obj.id}" /> </aura:iteration> </div> </aura:component>
({ doInit: function(cmp, event, helper) { var objs = [ {id: 11, txt: 'First object'}, {id: 12, txt: 'Second object'}, {id: 13, txt: 'Third object'} ]; cmp.set('v.someObjs', objs); }, changeObjectTxt: function(cmp, event, helper) { var chCmp = cmp.find('item_12'); console.log(chCmp); } })
I would structure your component a bit differently though and do this via a Lightning event. For instance, create an application event that you fire in your "changeObjectTxt" method, and then implement a handler in the simplechildcomponent that calls its own controller method.
All Answers
I would structure your component a bit differently though and do this via a Lightning event. For instance, create an application event that you fire in your "changeObjectTxt" method, and then implement a handler in the simplechildcomponent that calls its own controller method.
and the get it in controller by: