+ 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">
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:
<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"/>

    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}"/>