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[]" />

1 Answer 1

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.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.