Currently I develop a Lightning Component, which should show record details based on specific record field values.
Therefore I want to set dynamically component attributes based on some record values.
My current approach is to use a map attribute in the component, which contains the field name and the related values (<aura:attribute name="attribValuesMap" type="Map" />
).
The related APEX controller returns a Map @AuraEnabled public static Map<String,String> getSpecificRecordValues(Id recordId){}
and in the JS controller I set the component map attribute via callback.
Using debugging I see that the map contains the correct values - so this part works.
In the JS controller (doInit method) I want to iterate over this map to set other component attributes based on the map content, but this fails.
I always receive an error message like ".keys is no function", if I try something like:
var keyArr = Array.from(attribValuesMap.keys());
It seems that no "real" map is used, but a generic object.
Do you have another solution for me how to set dynamically component attributes based on record field values or can you let me know based on my approach how to iterate over maps in a JS controller?
Map
is a validaura:attribute type
it is not the same as aMap
object in JavaScript. I would recommend usingObject.keys(attribValuesMap)
instead or, even better, usingforce:recordData
to load a record with the fields you need, no custom Apex necessary.