how to detect aura:iteration has loaded?

I need to trigger a jQuery from Rerender after my aura:iteration has completed. Based on the official document, rerender fires each time when there is a event. But the my javascript code needs to be executed once after aura:iteration has loaded. I also found that there is an attribute call “loaded” in aura:iteration. But I can’t find any reference on how to access aura:iteration’s loaded attribute from renderer file.

Answer

I didn’t have time to write a full sample, but here’s some sample component markup for binding the loaded attribute to an aura:attribute:

<aura:attribute name="items"           type="String[]" default="['one', 'two', 'three']"/>
<aura:attribute name="iterationLoaded" type="Boolean"  default="false"/>

<aura:iteration items="{!v.items}" var="item" loaded="{!v.iterationLoaded}">
    Item = {!item}<br/>
</aura:iteration><br/>

itemsLoaded = {!v.iterationLoaded}

When I put this on a page, the items display and the iterationLoaded attribute displays as true.

It should be possible to put a change handler on the iterationLoaded attribute so that when it changes from false to true, a controller method is called which can run any needed code.

Or, an afterRender method could check that this attribute is true before doing any further processing.

Hope this helps!

Attribution
Source : Link , Question Author : WenHao , Answer Author : Florissant53

Leave a Comment