1

I have a number of <lightning:select> components in an iteration like so:

<aura:iteration items="{!v.data}" var="obj">
    <div class="slds-grid">
        <div class="slds-size_1-of-2">
            {!obj.Name}
        </div>
        <div class="slds-size_1-of-2">
            <lightning:select name="{!obj.Id}" value="{!obj.Role}" onchange="{!c.changeRole}">
                <option>Primary</option>
                <option>Secondary</option>
                <option>Other</option>
            </lightning:select>
        </div>
    </div>
</aura:iteration>

Each of these deals with a particular record, so when a change is made, I need to know the Id, as well as the new value of the select. My method:

changeRole: function(component, event, helper) {
    var val = event.getParam('value');
    val id = event.getParam('name');
    console.log(id+'-->'+val);
}

...ends up printing "undefined-->undefined" to the console every time.

I know that the prescribed method of getting these values is to use component.find('aura-id').get('v.value'), but that requires my selects to be static, not dynamic. I also know that I've successfully used getParam in similar situations in the past.

How can I get the values I need?

4

You can try to use event.getSource()

changeRole: function (component, event, helper) {
   const value = event.getSource().get('v.value');
   const name = event.getSource().get('v.name');
}

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.