+ Start a Discussion
LUIGI EMANUEL TAORMINALUIGI EMANUEL TAORMINA 

how to insert a record in the Component list?

as you can see I have created a lightning: datatable where through a list I show the products. When I go to select the single product to add to the cart, a popup opens, the popup contains a lightning: input that allows you to enter the quantity you want of that product. at the click of the "yes" button through the aura attributes I go to take AvailableQuantity of the selected product that is inside a list and subtract for the quantity entered by the user. my intent and set the list with the value of the updated AvailableQuantity field.
look at the line with the comment problem
Controller:
getSelectedProd: function (component, event) {
            component.set("v.popup",true);
            var selectedRows = event.getParam('selectedRows');
            console.log('selRows -> ' + JSON.stringify(selectedRows));
            var selectedRowsIds = [];
                for(var i=0;i<selectedRows.length;i++){
            selectedRowsIds.push(selectedRows[i].Id);
            component.set("v.AQuantity",selectedRows[i].AvailableQuantity__c);
            component.set("v.Name", selectedRows[i].Name__c);
            component.set("v.id", selectedRows[i].Id);
        }     
        component.set( "v.prodList2", selectedRows );           
        var list = component.get("v.prodList2");
        component.set('v.Counter', list.length);
        if(list.length==0){
            component.set("v.control",false);
        }
        else{
            console.log("Size = "+list.length);
        }
    },
    handleClick : function (component, event, helper) {
        component.set( "v.control", true );
        
    },
    yesBtn : function(component,event,helper){
        var qty=component.find("prova").get("v.value");
        var name=component.get("v.Name");
        var aquantity=component.get("v.AQuantity");
        console.log("id book "+component.get("v.id"));
        if(qty>aquantity){
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                title : 'Error',
                message: 'the quantity you want exceeds that available',
                duration:' 5000',
                key: 'info_alt',
                type: 'Error',
                mode: 'pester'
            });
            toastEvent.fire();
        }
        else{
            var rquantity=aquantity-qty;
            console.log("Available quantity - quantity = " +rquantity);
            //problem
            console.set("v.prodList2[v.id].AvailableQuantity__c",rquantity);
        }
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            title : 'Success',
            message: name+' added to cart quantity ='+quality,
            duration:' 5000',
            key: 'info_alt',
            type: 'success',
            mode: 'pester'
        });
        toastEvent.fire();
        component.set( "v.popup", false );
    }

 
PriyaPriya (Salesforce Developers) 

Hey Luigi,

I did not understand the issue here. Can you please help me to understand the issue by elaborating it.

Regards,

Priya Ranjan