1

I would like to pass an array of objects from my js file to an aura attribute. I know the list contains values and is correct before I pass it to the aura component but the list is empty when I log that attribute to the console.

Helper method:

//convert map into list of objects for Aura
                var objects = [];
                for(var rawLineItem in result.rawLineItemToContactIdList) {
                    objects.push({key:rawLineItem, value:result.rawLineItemToContactIdList[rawLineItem]});
                    console.log('objects: ' + JSON.stringify(objects));
                }
                component.set("v.objectList", objects);

Aura attribute:

<aura:attribute name="objectList" type="List" />

EDIT: Then I log the objectList varible to the console:

Aura:

<button class="slds-button slds-button_brand" onclick="{!c.showDupes}" >Log</button>

Helper:

showDupes: function(component, event, helper) {
        var objectList = component.get("v.objectList");

        console.log('objectList: ' + JSON.stringify(objectList));
    },
6
  • I am not sure why this fails. Try setting it to Object[] and see if that works for you. Commented Jul 17, 2018 at 15:16
  • Thanks @SebastianKessel, I already tried that but still no luck. It's weird because when i console.log the objects it is showing, but then when I log the objectList attribute it's empty
    – tom_12321
    Commented Jul 17, 2018 at 15:17
  • 2
    Something else must be at play there. Is there any other code futzing with that attribute? Are you in an architecture with inheritance? More details would be appreciated. Commented Jul 17, 2018 at 15:18
  • How does the problem manifest itself? Can you clarify the "not accepting" part?
    – POZ
    Commented Jul 17, 2018 at 15:21
  • I set objectList at the bottom of my Helper code after logging it to the console, knowing it's correct. Then I have a button which calls a function in the helper to console.log that attribute. I will add the code for that function
    – tom_12321
    Commented Jul 17, 2018 at 15:25

1 Answer 1

1

It was a dumb error where I passed in the aura component as 'cmp' instead of component. when i switched it form component.set("v.objectList", objects); to cmp.set("v.objectList", objects); it worked. Thanks for the help!

1
  • ha, nice catch, thanks for posting your solution =)
    – glls
    Commented Jul 17, 2018 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .