You need to sign in to do that
Don't have an account?
Expandable section Problem In Lightning
<!---Component--->
<div class="slds-p-around--large">
<aura:iteration items="{!v.CommunicatoActivity}" var="Act" indexVar="i">
<div class="slds-page-header" aura:id="{!i+'activity'}" style="cursor: pointer;" onclick="{!c.sectionOne}">
<section class="slds-clearfix" >
<div class="slds-float--left ">
<lightning:icon class="slds-show" aura:id="articleOne" iconName="utility:chevronright" size="xx-small" alternativeText="Indicates add"/>
<lightning:icon class="slds-hide" aura:id="articleOne" iconName="utility:chevrondown" size="xx-small" alternativeText="Indicates dash"/>
</div>
<div class='msgContainer'>
<aura:if isTrue="{!v.CommunicatoActivity.Type__c == 'Incoming'}">
<div class="iconContainer"><img src="{!$Resource.incomingSMS}" height="20" width="20" /></div>
<aura:set attribute="else">
<div class="iconContainer"> <img src="{!$Resource.outgoingSMS}" height="20" width="20" /></div>
</aura:set>
</aura:if>
<div class="numberContainer" ><a>{!Act.Phone_Number__c}</a></div>
<div style="margin-left: 15%;">
<p>You Sent a Message</p>
</div>
</div>
</section>
</div>
<div class="slds-hide slds-p-around--medium" aura:id="articleOne">
<p><strong>Type:</strong>{!Act.Type__c}</p>
<p><strong>Phone:</strong>{!Act.Phone_Number__c}</p>
<p><strong>Message:</strong>{!Act.Message__c}</p>
</div>
</aura:iteration>
</div>
<!------------Js----------->
doInit : function(component, event, helper) {
var action = component.get('c.getCommunicatoActivity');
action.setParams({ "recordId" : component.get("v.recordId") });
action.setCallback(this, function(response){
var state = response.getState();
if(state ==='SUCCESS'){
component.set('v.CommunicatoActivity',response.getReturnValue());
}else{
console.log('Some Error');
}
});
$A.enqueueAction(action);
},
sectionOne : function(component, event, helper) {
helper.helperFun(component,event,'articleOne');
},
<!-------Helper.Js---------------------->
helperFun : function(component,event,secId) {
var acc = component.find(secId);
for(var cmp in acc) {
$A.util.toggleClass(acc[cmp], 'slds-show');
$A.util.toggleClass(acc[cmp], 'slds-hide');
}
}
This is my code for expandable section in lightning component i get using aura:iteration
My problem is when i click on single section all section is exapanded
<div class="slds-p-around--large">
<aura:iteration items="{!v.CommunicatoActivity}" var="Act" indexVar="i">
<div class="slds-page-header" aura:id="{!i+'activity'}" style="cursor: pointer;" onclick="{!c.sectionOne}">
<section class="slds-clearfix" >
<div class="slds-float--left ">
<lightning:icon class="slds-show" aura:id="articleOne" iconName="utility:chevronright" size="xx-small" alternativeText="Indicates add"/>
<lightning:icon class="slds-hide" aura:id="articleOne" iconName="utility:chevrondown" size="xx-small" alternativeText="Indicates dash"/>
</div>
<div class='msgContainer'>
<aura:if isTrue="{!v.CommunicatoActivity.Type__c == 'Incoming'}">
<div class="iconContainer"><img src="{!$Resource.incomingSMS}" height="20" width="20" /></div>
<aura:set attribute="else">
<div class="iconContainer"> <img src="{!$Resource.outgoingSMS}" height="20" width="20" /></div>
</aura:set>
</aura:if>
<div class="numberContainer" ><a>{!Act.Phone_Number__c}</a></div>
<div style="margin-left: 15%;">
<p>You Sent a Message</p>
</div>
</div>
</section>
</div>
<div class="slds-hide slds-p-around--medium" aura:id="articleOne">
<p><strong>Type:</strong>{!Act.Type__c}</p>
<p><strong>Phone:</strong>{!Act.Phone_Number__c}</p>
<p><strong>Message:</strong>{!Act.Message__c}</p>
</div>
</aura:iteration>
</div>
<!------------Js----------->
doInit : function(component, event, helper) {
var action = component.get('c.getCommunicatoActivity');
action.setParams({ "recordId" : component.get("v.recordId") });
action.setCallback(this, function(response){
var state = response.getState();
if(state ==='SUCCESS'){
component.set('v.CommunicatoActivity',response.getReturnValue());
}else{
console.log('Some Error');
}
});
$A.enqueueAction(action);
},
sectionOne : function(component, event, helper) {
helper.helperFun(component,event,'articleOne');
},
<!-------Helper.Js---------------------->
helperFun : function(component,event,secId) {
var acc = component.find(secId);
for(var cmp in acc) {
$A.util.toggleClass(acc[cmp], 'slds-show');
$A.util.toggleClass(acc[cmp], 'slds-hide');
}
}
This is my code for expandable section in lightning component i get using aura:iteration
My problem is when i click on single section all section is exapanded
Did you find the solution? Currently I am facing the same problem in one of my requirement.
TIA.
aura:id doesn't support expressions. You can only assign literal string values to aura:id.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_ids.htm
You can use normal html id attribute and use the same to toggle the class
Thanks,
BaLa
You cannot use aura:id for this as it can take string values only as your sections are getting created dynamically so you can create the dynamic classes or id and can hide or show your component on the basis of that.
Hope, this will help you!!
Thanks