Any equivalent of apex:variable in Lightning Components?

In Visualforce apex:variable can be used to avoid the repetition of a Visualforce expression.

I have a collection returned from an @AuraEnabled method for which I want to do the same sort of thing that apex:variable does:

<aura:iteration var="item" items="{! v.items }">
    <!-- aura:variable does not exist: is there a way to do this in Lightning? -->
    <aura:variable var="sob" value="{! item.reference.sobReference }"/>
    <tr>
        <td>{! sob.Name }</td>
        <td>{! sob.Birthdate }</td>
        ...

Is there a way to do this in Lightning Components?

Answer

Yes,

You can use an attribute in the lightning component, and then set the value in your controller.

See

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_aura_attribute.htm

and

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_attr_values.htm

Edit: It seems like you’re just trying to alias an attribute you already have access to.

<aura:iteration var="item" items="{! v.items }">
<tr>
    <td>{! item.reference.sobReference.Name }</td>
    <td>{! item.reference.sobReference.Birthdate }</td>

    ...

Attribution
Source : Link , Question Author : Keith C , Answer Author : Ross Bassett

Leave a Comment