[SalesForce] How to pass parameter(indexVar of iteration) from lightning component to javascript controller

I have a requirement to pass parameter(indexVar of iteration) from lightning component to javascript controller.

<aura:iteration items="{!v.productListWrapper}" var="pro" indexVar="index">
    <ui:inputSelect aura:id="selectedproductWrapper" class="select-options inline" change="{!c.priceListChange}" value="{!v.priceListValue}"  >
            <aura:iteration items="{!pro.productPriceList}" var="priceList">
                <ui:inputSelectOption text="{!priceList.value}" label="{!priceList.label}"/>
            </aura:iteration>
      </ui:inputSelect>

I want to pass index to javascript controller when user select a value(pricelist) from input select option.

I am able to do this for anchor tag using data attribute but it's not working for input select.

 <a onclick="{!c.changePricelist" data-index="{!index}" ><u>ChangePriceList</u></a><br/>

Best Answer

Do you need the index or the value selected ? You can get the value using component.find("selectedproductWrapper").get("v.value");
If you really need the index I guess you can find the position of this value inside your list.

You can find code samples here.

Related Topic