function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Artem Artemenko 9Artem Artemenko 9 

Iterating through an custom object list

Hi. I return custom object to js by callback, then take it in aura component like ​​​​​.
<aura:attribute name="customObj" type="customObj__c[]"/>
Also i have list of custom fields in this object (endless) 
<aura:attribute name="listObjKeys" type="String" default='["Field1__c","Field2__c","Field3__c","Field1__c","Date__c"]'/>
How i can iterate through my object to display values by field. I try this, but with no result 
<aura:iteration items="{!v.customObj}" var="co">
  <aura:iteration items="{!v.listObjKeys}" var="keys">
    <tr>{!keys}</tr>
  </aura:iteration>
</aura:iteration>
Best Answer chosen by Artem Artemenko 9
Nayana KNayana K
Unfortunately, lightning component doesnt support this directly. You must create new component.
Say a child component:
<!--Child.cmp-->
<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="custObj" type="Object"/>
    <aura:attribute name="key" type="string"/>
    <aura:attribute name="val" type="string"/>
    <p>{!v.val}</p>
</aura:component>


 
<!--ChildController.js-->
({
    doInit : function(component, event, helper) {
        var key = component.get("v.key");
        var custObj= component.get("v.custObj");
        component.set("v.val" , custObj[key]);
    },
})


In main component change the iteration like this:
 
<aura:iteration items="{!v.customObj}" var="co">
  <aura:iteration items="{!v.listObjKeys}" var="key">
    <c:Child map="{!v.customObj}" key="{!key}"/>
  </aura:iteration>
</aura:iteration>