You need to sign in to do that
Don't have an account?

Data from wrapper class not visible in lightning component
Hi All,
I am working on a component where i am getting the results from an apex class and displaying it on the screen but i am not able to display and bind information on the screens eventhough i am stringifying the json.
Any help would be greatly appreciated.
Thanks,
Bharath
I am working on a component where i am getting the results from an apex class and displaying it on the screen but i am not able to display and bind information on the screens eventhough i am stringifying the json.
Component : <aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" controller="SaveDRLines"> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="drLines" type="list"/> <aura:attribute name="wrapperList" type="Object[]"/> <aura:attribute name="recordId" type="String" default="a0tE0000000qtxjIAA"/> <table class="slds-table slds-table_bordered slds-table_cell-buffer"> <thead> <tr class="slds-text-title_caps"> <!--header checkbox for select all--> <th scope="col"> <div class="slds-truncate" title="Name">Name</div> </th> <th scope="col"> <div class="slds-truncate" title="Price">Price</div> </th> <th scope="col"> <div class="slds-truncate" title="Quantity">Quantity</div> </th> </tr> </thead> <tbody> <aura:iteration items="{!v.wrapperList}" var="wr" ><!--indexVar="index"--> <th scope="row"> <div class="slds-truncate" title="{!wr.name}"> {!wr.name} </div> </th> <th scope="row"> <div class="slds-truncate" title="{!wr.price}"> <lightning:input name="price" style="width:250px!important" value="{!wr.price}" /> </div> </th> <th scope="row"> <div class="slds-truncate" title="{!wr.quantity}"> <lightning:input name="quantity" style="width:250px!important" value="{!wr.quantity}" /> </div> </th> </aura:iteration> </tbody> </table> </aura:component> JS Controller : ({ doInit : function(component, event, helper) { var JsonData='[{"Id":"01tE0000008kwYSIAY","Name":"924737217148","AlternateID__c":"924737217148","Family":"Conventional"},{"Id":"01tE0000008kwYTIAY","Name":"924737310100","AlternateID__c":"924737310100","Family":"Automotive Other"}]'; var array=JSON.parse(JsonData); var drId=component.get("v.recordId"); console.log('drId >>>> '+drId); var IdList=[]; for(let jo in array){ IdList.push(array[jo].Id); console.log(array[jo].Id); } component.set("v.drLines", JsonData); var action = component.get("c.returnDRLines"); action.setParams({productIdList:IdList, recordId: drId}); action.setCallback(this,function(response){ var state = response.getState(); if (state === "SUCCESS"){ console.log('SUCCESS'); //console.log('response.getReturnValue() >>>> '+JSON.stringify(response.getReturnValue())); var s= JSON.stringify(response.getReturnValue()); console.log('s value >>>> '+JSON.stringify(s)); component.set("v.wrapperList", s); //REDIRECT TO DR RECORD } else{ console.log('Error...'); //REDIRECT TO DR RECORD } }); $A.enqueueAction(action); } }) Apex controller : public class SaveDRLines { /*Display lines on ltng component*/ @AuraEnabled public static list<DRLineWrapper> returnDRLines( list<Id> productIdList, Id recordId){ list<Deal_Registration_Line__c> drLineList= new list<Deal_Registration_Line__c>(); list<PriceBookEntry> pbeList = new list<PriceBookEntry>(); list<DRLineWrapper> dwList = new list<DRLineWrapper>(); //ADD THE ROLE NAME FILTER TO GET THE RIGHT PRICEBOOK pbeList=[select Pricebook2.Name, Product2.Id, PriceBook2Id, Product2.Name, UnitPrice, Product2.ProductCode, Product2.Description, Product2.Family, Product2.Product_Line__c from PriceBookEntry where IsActive = true limit 10];//AND Product2.Id IN:productIdList for(PriceBookEntry pbe : pbeList){ DRLineWrapper dw= new DRLineWrapper(); dw.quantity=0; dw.name=pbe.Product2.Name; dw.price=pbe.UnitPrice; dw.productId=pbe.Product2Id; dw.drId=recordId; dwList.add(dw); } system.debug('dwList >>> '+dwList); /*for(PriceBookEntry pbe : pbeList){ Deal_Registration_Line__c drLine= new Deal_Registration_Line__c(); drLine.Deal_Registration__c=recordId; drLine.Quantity__c=wo.quantity; drLine.Unit_Price__c=wo.price; drLine.Product__c =wo.productId; drLineList.add(drLine); }*/ //insert drLineList; return dwList; } @AuraEnabled public static string insertDRLines(list<DRLineWrapper> drWrapList){ list<Deal_Registration_Line__c> drlineList = new list<Deal_Registration_Line__c>(); for(DRLineWrapper dw: drWrapList){ Deal_Registration_Line__c drLine= new Deal_Registration_Line__c(); drLine.Deal_Registration__c=dw.drId; drLine.Quantity__c=dw.quantity; drLine.Unit_Price__c=dw.price; drLine.Product__c=dw.productId; drlineList.add(drLine); } insert drlineList; return 'success'; } public class DRLineWrapper{ @AuraEnabled public String name{get;set;} @AuraEnabled public Integer quantity{get;set;} @AuraEnabled public decimal price{get;set;} @AuraEnabled public String productId{get;set;} @AuraEnabled public String drId{get;set;} } }
Any help would be greatly appreciated.
Thanks,
Bharath
The issue has been resolved
var s= response.getReturnValue();// I had to remove the json.stringify here