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
Nicole LevyNicole Levy 

Retrieve array stored in aura attribute

Hi, so I am storing an array in an aura attribute that is set up like so:

<aura:attribute name="events" type="Asset[]" />

but when I call component.get('v.events') a javascript proxy is returned, which is fine, but I'm not sure how to get the target array out of the proxy. Thanks in advance.
Best Answer chosen by Nicole Levy
Balagopal GBalagopal G

Hi,

you can also do something like :

<aura:attribute name="objectArray" type="SObject[]" default="[]"/>

in controller,

var obj=component.get('v.objectArray');
for(var i=0;i<obj.length;i++){
	var ob=obj[i];
}

now inside the loop , you can access the fields  by on.fieldAPI.

Hope this helps.

Regards
 

All Answers

Alain CabonAlain Cabon
Hi,

You shoud post the result for the console log (  Control + Shift + J under Chrome for accessing the console directly )

var myArray =  component.get('v.events');
console.log( JSON.stringify ( myArray ) );

 
Balagopal GBalagopal G

Hi,

you can also do something like :

<aura:attribute name="objectArray" type="SObject[]" default="[]"/>

in controller,

var obj=component.get('v.objectArray');
for(var i=0;i<obj.length;i++){
	var ob=obj[i];
}

now inside the loop , you can access the fields  by on.fieldAPI.

Hope this helps.

Regards
 

This was selected as the best answer