0

I need to make an array for iteration selected objs in future. But when I push needed element, it updates. It's because I always call a new var: var objs = []; How can I add the element right?

My code:

var objs = [];
objs.push(objs);
objs.push(event.getSource().get("v.name"));
component.set('v.objs', objs);

In cmp:

<aura:attribute name="objs" type="MyObject__c[]" />
3

You need to start from your existing data rather than initializing an empty array.

var objs = component.get('v.objs');
objs.push(event.getSource().get("v.name"));
component.set('v.objs', objs);

Your current code will not accumulate objects because it always overwrites from a blank array plus the latest value.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.