1

I have a JSON and I parse it. Finally I this is my class for parsing the JSON :

public class InterlocuteursParser {

    public class Interlocuteurs {
        public String contact;
        public String postalcode;
        public String contactnumber;
    }

    public List<Interlocuteurs> Interlocuteurs;
}

In my lightning component I have an attribute Interlocuteurs (type : List) which is initialized with a List<Interlocuteurs>.

I have an attribute called att which is a list of String and initialize with ["contact","postalcode","contactnumber"].

I want to display in my component the values of attribute for each Interlocuteurs in my List of Interlocuteurs. I try :

<aura:iteration items="{!v.Interlocuteurs}" var="Interlocuteurs">
     <aura:iteration items="{!v.att}" var="att">
          {!Interlocuteurs}.{!att}
     </aura:iteration>
</aura:iteration>

Or

<aura:iteration items="{!v.Interlocuteurs}" var="Interlocuteurs">
     <aura:iteration items="{!v.att}" var="att">
          {!Interlocuteurs.att}
     </aura:iteration>
</aura:iteration>

If I write only {!Interlocuteurs.contact} the value of contact of my Interlocuteur is displayed.

But it doesn't work. How can I fix it?

EDIT from review queue on 07/14/2018

Thank you for your response.

If I have Interlocuteur with : - contact = 1 - postalcode = 51100 - contactnumber = 50

My Component :

<aura:component controller="testmecontroller5parser">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute type="List" name="Interlocuteurs"/>
    <aura:attribute type="List" name="getAtt" default="['contact','postalcode','contactnumber']"
    hello: {!v.Interlocuteurs}
    <aura:iteration items="{!v.Interlocuteurs}" var="Interl">
        <aura:iteration items="{!v.getAtt}" var="att">
             hello : {!Interl.att}
        </aura:iteration>
     </aura:iteration>
</aura:component>

But it doesn't work... I want display all values of all attributes of my List Interlocuteurs with iterations.

1

For client to apex methods/variable you need @AuraEnabled annotation AuraEnabled Annotation

You may have to annotate every property you are accessing in your component with @AuraEnabled.

The @AuraEnabled annotation enables client- and server-side access to an Apex controller method. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_AuraEnabled.htm

Component:

<aura:component controller="testmecontroller5parser" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute type="List" name="Interlocuteurs"/>
    hello: {!v.Interlocuteurs}
    <aura:iteration items="{!v.Interlocuteurs}" var="Interl">
        hello : {!Interl.contact}
    </aura:iteration>
</aura:component>

Controller:

({
    doInit : function(cmp, event, helper) {
        var action = cmp.get("c.getInterlocuteurs");

        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set('v.Interlocuteurs', response.getReturnValue());
            console.log(cmp.get('v.Interlocuteurs'));
            }

        });
        $A.enqueueAction(action);
}

})

Apex controller:

public class testmecontroller5parser {

    public class testmecontroller5 {
        @AuraEnabled
        public String contact;
        @AuraEnabled
        public String postalcode;
        @AuraEnabled
        public String contactnumber;
    }

    @AuraEnabled
    public static List<testmecontroller5> getInterlocuteurs(){
        List<testmecontroller5> Interlocuteurs = new List<testmecontroller5>();
        testmecontroller5 tst = new testmecontroller5();
        tst.contact = 'contact 1';
        Interlocuteurs.add(tst);
        return Interlocuteurs;
    }
}

Output: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.