Accordion in Lightning

Data.cmp
------------
<aura:Component controller="ContactList">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="conList" type="List"/>
   
    <div class="slds-m-around_x-large">
       
        <lightning:accordion >
         <aura:iteration items="{!v.conList}" var="con">
                <lightning:accordionSection name="{!con.name}" label="{!con.Name}">
                    <aura:set attribute="body">
                        Name{!con.Name}<br/>
                        Email{!con.Email}<br/>
                        FirstName{!con.FirstName}<br/>
Phone{!con.Phone}
                 </aura:set>
                </lightning:accordionSection>
               </aura:iteration>
           </lightning:accordion>
       
      </div>
 
</aura:Component>


Controller
-------------
({    
    doInit: function(component,event,helper){
        var action = component.get('c.getContactData');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === 'SUCCESS' && component.isValid()){
                console.log('checking the status ');
                 component.set('v.conList', response.getReturnValue());
                
            }else{
                alert('There might be someproblem');
            }
        });
        $A.enqueueAction(action);
    }
})

Apex class
-------------
Public class ContactList{
    @AuraEnabled
public static List<Contact> getContactData(){
List<Contact> condata=new List<Contact>();
for(Contact con:[select Name,Email,FirstName,Phone from Contact]){
condata.add(con);
}
return condata;

}
}


Lightning Application
----------------------------
<aura:application extends="force:slds" >
    <c:Data/>
</aura:application>








Comments