function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amit BehereAmit Behere 

http://salesforce.stackexchange.com/questions/77730/lightning-component-auraiteration-is-throwing-error-upon-rerendering

Hello, 
i am getting following error 
User-added image
Sorry to interrupt
This page has an error. You might just need to refresh it. Action failed: aura:iteration$controller$itemsChange [Cannot read property 'config' of undefined] Failing descriptor: {aura:iteration$controller$itemsChange}

config is not used in my JS then also  i am getting the  error

JS Code
 
removeDeletedRow: function(component, event, helper) {
        // get the selected row Index for delete, from Lightning Event Attribute  
     var index =event.getParam("indexVar"); //here i am getting exact index 
        //  var index= event.getSource().get("v.tabindex");
       // var index=event.currentTarget.Dataset.index;
    console.log("index>>>>>>>>>>>>"+index);
        // get the all List (contactList attribute) and remove the Object Element Using splice method    
        var AllRowsList = component.get("v.bookingList");
       
        AllRowsList.splice(index, 1);
        
        // set the contactList after remove selected row element  
        component.set("v.bookingList", AllRowsList);
      
    },

in above js function i am getting error which i mention above

Component code
<aura:iteration items="{!v.bookingList}" var="obj" indexVar="index">
      <span>
                <tr class="slds-text-title_caps">
                    <td> 
                          <h1>{!index}</h1>
                    </td>
                    <td>
                        <lightning:input class="slds-input"  text="{!index}" name="{!'DES_'+index}" value="{!obj.Description__c}"/>
                    
                    </td>
                    <td>
                        <lightning:input class="slds-input"   text="{!index}" name="{!'AMT_'+index}" value="{!obj.Amount__c}" required="true"/>
         
                    </td>
                    <td>
                        <lightning:input type="checkbox"   text="{!index}" name="{!'CHECK_'+index}" checked="{!obj.IsBooking__c}" onchange="{!c.updateAmount}"/> 
                        
                    </td>
                    <td>
                        <lightning:input class="slds-input"   text="{!index}" name="{!'GROSS_'+index}" value="{!obj.GrossAmount__c}" readonly=""  />
                    </td>
                    <td>
                        <lightning:button  tabindex="{!index}" value="{!index}" onclick="{!c.removeDeletedRow}" label="Delete"/>
<a  data-index="{!index}" onclick="{!c.removeRow}">Delete</a>
            
                    </td> 
                </tr>
                </span> 
            </aura:iteration>

In any solution help me out.... 



 
Alain CabonAlain Cabon
Hi,

A simple trick is to use: name
 
<td><lightning:button name="{!index}" onclick="{!c.removeDeletedRow}" label="Delete"/></td>
 
removeDeletedRow: function(component, event, helper) {
        var index = event.getSource().get("v.name");
        console.log("index:"+index);  
        var AllRowsList = component.get("v.bookingList");
        AllRowsList.splice(index, 1);
        component.set("v.bookingList", AllRowsList);        
 },
Amit BehereAmit Behere
Thank you Alain Cabon for replying, but i am getting exact id what i want but thing is that i am getting same error which i mention above.
Alain CabonAlain Cabon
My sample code works fine (tested).
Amit BehereAmit Behere
CMP Code
<!--Parent Lightning Compomemt-->
<aura:component controller="addDeleteController" Implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <!--Init handler which is call doInit js function on component Load-->  
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
     
    <!--Event handler for Add and Delete Row Event which is fire from Child Component-->  
     <aura:attribute name="bookingList" type="BookingDetails__c[]"/>
    <aura:handler name="DeleteRowEvt" event="c:DeleteRowEvt" action="{!c.removeDeletedRow}"/>
    <aura:handler name="AddRowEvt" event="c:AddNewRowEvt" action="{!c.addNewRow}"/>
    <aura:attribute name="rowIndex" type="Integer"/>
    <aura:registerEvent name="DeleteRowEvt" type="c:DeleteRowEvt"/> 
    <aura:registerEvent name="AddRowEvt" type="c:AddNewRowEvt"/> 
     <aura:attribute name="contactId" type="Contact"/>
    <!--Aura Attribute for store Contact Object List as Array-->    
    <aura:attribute name="contactList" type="Contact[]"/> 
    <!--Fetch booking data start-->  
    <!-- <aura:attribute name="bookingList" type="BookingDetails__c[]"/>
  <aura:iteration items="{!v.bookingList}" var="obj2">
         <h1 class="slds-page-header__title"> {!obj2.Description__c}</h1>
        </aura:iteration>-->
    <!--Fetch booking data end-->
    <!--Header Part-->        
    <div class="slds-page-header">
        
        
        <h1 class="slds-page-header__title">Add Booking</h1>
        <p class="slds-text-body_small slds-line-height_reset"></p>
    </div>
    
    <!--Buttons-->
    <lightning:button onclick="{!c.AddNewRow}" value="changeIt" label="Add Booking" />
    <!--Save Button which is call Save js function on click --> 
    <lightning:button class="" onclick="{!c.Save}" label="Save"/>
    <!--Table Part-->  
    
    <table class="slds-table slds-table_bordered slds-table_cell-buffer"> 
        <thead>
            <tr class="slds-text-title_caps">
                <th scope="col">
                    <div class="slds-truncate">Sr.No</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Description">Description</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Amount">Amount</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Is Booking">Is Booking</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Gross Amount">Gross Amount</div>
                </th>
            </tr>
        </thead>   
        <tbody>
            <!--Iterate the child Component for display Table rows 
               with pass the List Item Index for track the Every child Component 
               and pass each List Contact Instance -->         
         <!--   <aura:iteration items="{!v.bookingList}" var="item" indexVar="indeex">
                <c:dynamicRowItem bookingList="{!item}" rowIndex="{!indeex}" ContactInstance="{!v.bookingList}"/>
            </aura:iteration>
-->
            <aura:iteration items="{!v.bookingList}" var="obj" indexVar="index">
                
                <tr class="slds-text-title_caps">
                    <td> 
                        <h1>{!index+1}</h1>
                    </td>
                    <td>
                        <lightning:input class="slds-input"  text="{!index}" name="{!'DES_'+index}" value="{!obj.Description__c}"/>
                        
                    </td>
                    <td>
                        <lightning:input class="slds-input"   text="{!index}" name="{!'AMT_'+index}" value="{!obj.Amount__c}"  onkeyup="{!c.updateAmount}" required="true" />
                        
                    </td>
                    <td>
                        <lightning:input type="checkbox"   text="{!index}" name="{!'CHECK_'+index}" checked="{!obj.IsBooking__c}" onchange="{!c.updateAmount}"/> 
                        
                    </td>
                    <td>
                        <lightning:input class="slds-input"   text="{!index}" name="{!'GROSS_'+index}" value="{!obj.GrossAmount__c}" readonly=""  />
                    </td>
                    <td>
                       <lightning:button   value="{!index}" onclick="{!c.removeRow}" label="Delete"/> 
                      <!--  <a  data-index="{!index}" onclick="{!c.removeRow}">Delete</a>
                           <a onclick="{!c.removeRow}">  <button class="slds-button slds-button_brand" id="{!index}"  value="{!index}" onclick="{!c.removeRow}">Delete</button>
                            <lightning:icon variant="error"   iconName="utility:delete" class="slds-icon slds-icon_small" size="small" alternativeText="icon"/>
                            <span class="slds-assistive-text">Delete Icon</span>
                        </a>-->
                    </td> 
                </tr>
                
            </aura:iteration>
        </tbody>
    </table>
    <br/>
    
</aura:component>

JS Code
({
    
    // function call on component Load
    doInit: function(component, event, helper) {
        // create a Default RowItem [Contact Instance] on first time Component Load
        // by call this helper function  
        helper.createObjectData(component, event);
        helper.updateGrossAmount(component, event, helper); 
    },
    //to get the selected contact Id
    getContactId:function(component, event, helper) {
        
    },
    // function for save the Records 
    Save: function(component, event, helper) {
        // first call the helper function in if block which will return true or false.
        // this helper function check the "first Name" will not be blank on each row.
        if (helper.validateRequired(component, event)) {
            // call the apex class method for save the Contact List
            // with pass the contact List attribute to method param.  
            var action = component.get("c.saveContacts");
            var boookingList=component.get("v.bookingList");
            var contactdata=component.get("v.contactId");
            action.setParams(
                
                {BookingDetailsList : JSON.stringify(boookingList), ContactData:JSON.stringify(contactdata)}
            );
            // set call back 
            action.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") {
                    // if response if success then reset/blank the 'contactList' Attribute 
                    // and call the common helper method for create a default Object Data to Contact List 
                   // component.set("v.bookingList", []);
                    //helper.createObjectData(component, event);
                    alert('record Save');
                }
            });
            // enqueue the server side action  
            $A.enqueueAction(action);
        }
    },
       // function for delete the row 
    removeDeletedRow: function(component, event, helper) {
        // get the selected row Index for delete, from Lightning Event Attribute  
    var index =event.getParam("indexVar");
     // var index=  parseInt(event.getSource().get("v.value"));
        //  var index= event.getSource().get("v.tabindex");
       // var index=event.currentTarget.Dataset.index;
    console.log("index>>>>>>>>>>>>"+index);
        // get the all List (contactList attribute) and remove the Object Element Using splice method    
        var AllRowsList = component.get("v.bookingList");
       
        AllRowsList.splice(index, 1);
        
        // set the contactList after remove selected row element  
        component.set("v.bookingList", AllRowsList);
      
    }, 
    // function for create new object Row in Contact List 
    addNewRow: function(component, event, helper) {
        // call the comman "createObjectData" helper method for add new Object Row to List  
        helper.createObjectData(component, event);
    },

    AddNewRow : function(component, event, helper){
        // fire the AddNewRowEvt Lightning Event 
        component.getEvent("AddRowEvt").fire();     
    },
    removeRow : function(component, event, helper){
        //var v= parseInt(event.target.value);
  var v=parseInt(event.getSource().get("v.value"));
        alert(v);
        // fire the DeleteRowEvt Lightning Event and pass the deleted Row Index to Event parameter/attribute
        component.getEvent("DeleteRowEvt").setParams({"indexVar" : v}).fire();
    //helper.updateGrossAmount(component, event, helper);
    
    }, 
    
    //to get calculated value for booking
    updateAmount: function(component, event, helper){
        var bookedList=component.get("v.bookingList");
       // var completeList=component.get("v.ContactInstance");
        //console.log("bookedList111111>>>>>>>>>>>>>"+JSON.stringify(completeList));
        
        var selected=event.getSource().get("v.name");
        var index=selected.split('_');
        //var v="AMT_";
        
        var mydd=bookedList[parseInt(index[1])];
        console.log("bookedList>>>>>>>>>>>>>"+JSON.stringify(bookedList));
        if(bookedList[parseInt(index[1])]["Amount__c"]!=""){
            if(bookedList[parseInt(index[1])]["IsBooking__c"]==true){
                
                bookedList[parseInt(index[1])]["GrossAmount__c"]=bookedList[parseInt(index[1])]["Amount__c"];
               }
            else{
                bookedList[parseInt(index[1])]["GrossAmount__c"]=0;
            }
        }
        else{
            
            alert("Enter the Amount First");
        }
        var amtTotal=0;
        var bookedListLength=bookedList.length;
        
        helper.updateGrossAmount(component, event, helper);       
    },

    
    
})

​​​​​​​
Alain CabonAlain Cabon
You don't need to fire an event. 

removeRow is sufficient alone.
 
<lightning:button  value="{!index}" onclick="{!c.removeRow}" label="Delete"/>
 
removeRow: function(component, event, helper) {
        var index = parseInt(event.getSource().get("v.value"));
        console.log("index:"+index);  
        var AllRowsList = component.get("v.bookingList");     
        AllRowsList.splice(index, 1);
        component.set("v.bookingList", AllRowsList);        
},

 
Amit BehereAmit Behere
Hey,
Alain Cabon,
Thanks for your help to solve the problem,

removeRow is sufficient alone is correct but my problem was different.
and i solved  that "config undefiend" problem by just replacing the following 

<lightning:input class="slds-input" text="{!index}" name="{!'DES_'+index}" value="{!obj.Description__c}"/>

with

<lightning:input class="slds-input"   value="{!obj.Description__c}"/>

i.e. by removing the "name" and "text" property of "<lightning:input >" from my code because it is conflicting the aura iteration.