[SalesForce] Getting selected values in aura:iteration

I have a problem to retrieve some values within some picklists.
Here is my code of the lightning component:

<div class="c-container">
        <lightning:layout horizontalAlign="space">
            <lightning:layoutItem flexibility="auto" padding="around-small" size="6">
                <div id="pklProperty1" text="primo gruppo: " name="selectProperty" hidden="true">
                    <aura:iteration items="{!v.Property1}" var="Prodotto">

                        <aura:if isTrue="{!Prodotto.NE__Type__c == 'Enumerated'}">
                            <lightning:select aura:id="pklProductFamilies" label="{!Prodotto.Name}">
                                <aura:iteration items="{!Prodotto.NE__PropertyDomains__r}" var="pd">
                                    <option aura:id="propertiesDomain" value="{!pd.Id}">{!pd.Name}</option>
                                </aura:iteration>
                            </lightning:select>
                            <aura:set attribute="else">
                                <lightning:input label="{!Prodotto.Name}" name="{!Prodotto.Id}" />
                            </aura:set>
                        </aura:if>

                        <br/>
                    </aura:iteration>
                </div>
            </lightning:layoutItem>
        </lightning:layout>
    </div>

And here is the code in the controller where I try to retrieve the selected values:

verify : function(component, event, helper) {
        var items = component.find("propertiesDomain");
        console.log("items[0]: "+items[0].value + " items[1]: " + items[1].value);      
    }

But the returned values are undefined. I also try to change this line:

var items = component.find("propertiesDomain");

to this:

var items = component.find("propertiesDomain").get("v.value");

But I get this error:

This page has an error. You might just need to refresh it. Action failed: c:AnagraficaMateriali$controller$verify [component.find(...).get is not a function] Failing descriptor: {c:AnagraficaMateriali$controller$verify}

Could anybody know how to resolve?
Thanks in advance.

Best Answer

To get the value selected you need to target the lightning:select and get his value, because if you target the options they will all have the same aura:id as it does not support expressions (so there's no way to create dynamic ones).

Related Topic