2

I am using lightning:accordion component. When ever I am setting some value in it first time it is working fine. But when I change my value it is giving me an error.

<lightning:accordion aura:id="accordion" activeSectionName="{!v.object}">
                                    <aura:iteration items="{!v.objectList}" var="sObject">
                                            <lightning:accordionSection name="{!sObject.name}" label="{!sObject.label}">
                                                    <aura:set attribute="body">
                                                        <aura:iteration items="{!sObject.items}" var="item">
                                                            <c:picklistOption label="{!item.label}" name="{!item.name}" selected="{!v.selectedListView}" onSelect="{!c.onListViewSelect}" />
                                                        </aura:iteration>
                                                    </aura:set>
                                            </lightning:accordionSection>
                                    </aura:iteration>
                                </lightning:accordion>

in my js on doint I am setting some value.

doint: function(component){
   component.set('v.objectsList':[{
         name : 'contact',
         label : 'contact',
         items : [{
             name : 'test contact',
             label : 'Test Contact'         
         }]
}]);
}

Then it is working fine.

But if on any other event I am changing values like

onChange: function(component){
       component.set('v.objectsList':[{
             name : 'lead',
             label : 'lead',
             items : [{
                 name : 'test lead',
                 label : 'Test lead'         
             }]
    }]);
    }

when I set above value and try to open any accordion it is giving me error

lightning:accordion$controller$handleSectionSelect [Cannot read property 'close' of undefined] Failing descriptor: {lightning:accordion$controller$handleSectionSelect}

2
  • You are referring close property of some variable which its complaining does not exists. In you code I cannot see anything causing issue. try commenting few lines until error goes away?
    – Raul
    Nov 13 '17 at 10:06
  • Actually error is coming in accordion as given in error stack Nov 13 '17 at 10:07
3

Seems like when you are loading the initial data, you are introducing a contact item to your lightning:accordion. But after doing a change you remove it, by just replacing it with lead.

So when it refreshes, it trys to close contact and open lead, but you stole the contact already from your data.

Try to push the new value, without overriding the old value, if this is an option for you:

onChange: function(component){
    var obejcts = component.get('v.objectsList');

    obejcts.append({
         name : 'lead',
         label : 'lead',
         items : [{
             name : 'test lead',
             label : 'Test lead'         
         }]
    });

    component.set('v.objectsList', objects);
}

If this isn't an option for you, consider adding a isRendered attritbute and hide the element when you don't need it, so you won't need to refresh the whole component/page.

var types = component.get('v.objectsList');

for(var sObjectType of types) {
    sObjectType.isRendered = false;
}

types.append({
    name : 'lead',
    label : 'lead',
    isRendered : true,


<lightning:accordionSection class="{!sObject.isRendered ? '' : 'slds-hide'}" 
                            name="{!sObject.name}" label="{!sObject.label}">
2
  • yes @basti you are right with your observation. But my use case is to replace content thats why problem is cominng Nov 13 '17 at 10:33
  • @ManjotSingh updated my answer.
    – Basti
    Nov 13 '17 at 10:54

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.