You need to sign in to do that
Don't have an account?

How to use dynamic property names to access an object.
I am creating a generic list component that takes in an object type, and a list of fields that it wants to display. I am looping through each of the items and building a table, but when it comes to outputting the different fields, I am at a bit of a roadblock for doing it dynamically. Here is the relevant component code:
In the aura:iteration in the tbody, I am trying to cycle through the different field names, and then grab those fields from the item, but it doesn't seem like lightning supports it. For example if objectFields contained an array of strings containing ["Id","Name"], I want to then grab item.Id and item.Name and display them in the table. But using {!item.field} or anything similar does not seem to work.
Could anyone provide me with the proper syntax if this is possible, or a possible workaround to get something like this to work?
<aura:component description="ObjectList" controller="ObjectListController"> <aura:attribute name="objectName" type="String" default="" /> <aura:attribute name="objectFieldsString" type="String" default="Id,Name" /> <aura:attribute name="objectFields" type="List" /> <aura:attribute name="items" type="List" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <table> <thead> <tr> <aura:iteration items="{!v.objectFields}" var="fieldName"> <th scope="col"><div class="slds-truncate">{!fieldName}</div></th> </aura:iteration> </tr> </thead> <tbody> <aura:iteration items="{!v.items}" var="item"> <tr> <aura:iteration items="{!v.objectFields}" var="field"> <td> {!item.field} </td> </aura:iteration> </tr> </aura:iteration> </tbody> </table> </aura:component>
In the aura:iteration in the tbody, I am trying to cycle through the different field names, and then grab those fields from the item, but it doesn't seem like lightning supports it. For example if objectFields contained an array of strings containing ["Id","Name"], I want to then grab item.Id and item.Name and display them in the table. But using {!item.field} or anything similar does not seem to work.
Could anyone provide me with the proper syntax if this is possible, or a possible workaround to get something like this to work?
I have a similar scenario. Any luck with it?
<design:attribute name="objectName" label="Object Name"/>
and set that attribute while dploying component in properties.