Lightning: Expression to get dynamic field on Object/SObject

In VF it is possible to do like:

<apex:outputField value="{!target[dynProperty]}"/>

Which expression can be used to do similar thing inside lightning component (not inside lightning js controller)? Doing like this

{!v.target[dynProperty]}

results in error:

Failed to save undefined: expecting a positive integer, found ‘dynProperty’ at column 10 of expression: v.target[dynProperty]: Source

Are there any ideas how to do this inside component (not js controller)?

Answer

The expression syntax does not support it.

You can use index array referencing, but not what you are doing here.

{!v.target[3]} – Okay

{!v.target.prop} – Okay

What you suggested, no joy.

Attribution
Source : Link , Question Author : Natallia , Answer Author : Ratan Paul

Leave a Comment