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

how to access object values in lightning component
I want to render a table dynamically in lightning. I have a list of data of transaction (Custom object) and list of string which contains API name which data i want to render.
I have created a child component and wrapped it in nested aura iteration to display the data. But I am unable to access the value.
child component
___________________
controller
__________
debug value in the obj :
debug value in the field :
I have created a child component and wrapped it in nested aura iteration to display the data. But I am unable to access the value.
aura:iteration items="{!v.Transactions}" var="trans"> <tr> <aura:iteration items="{!v.fieldNames}" var="field" indexVar="ind"> <td><c:TransactionOutputField object="{!trans}" fieldName="{!field}"/></td> </aura:iteration> </tr> </aura:iteration>
child component
___________________
<aura:component> <aura:attribute name="object" type="Object" /> <aura:attribute name="fieldName" type="String" /> <aura:attribute name="fieldVal" type="String" access="private" /> <aura:handler name="init" value="{!this}" action="{!c.myAction}"/> {!v.fieldVal} </aura:component>
controller
__________
({ myAction : function(component, event, helper) { var obj = component.get("{!v.object}"); var field = component.get("{!v.fieldName}"); console.log(JSON.stringify(obj)); console.log(field); var value = obj.field; console.log(value); component.set("v.fieldVal", value); } })
debug value in the obj :
{"Id":"a0l1q000000BYLQAA4","Name":"0002000332","akritiv__Amount__c":0,"akritiv__Balance__c":0,"akritiv__Source_System__c":"SAPG","akritiv__Batch_Number__c":"20181003124027"}
debug value in the field :
akritiv__source_system__c
You can access object property using key value pair in Javascript.
Like : String fieldValue = object["fieldName"];
Please refer below JS controller code.
I am only getting the value for the Name field. And for other custom field I am getting "Undefined"
I tried below code snipped and it is showing me correct values
May be your browser chaching is enabled so values in debug are not getting refreshed.
Can you disable "Enable secure and persistent browser caching to improve performance" from session sessting and refresh page one more time.