4

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/>
4
  • can you try this below code.<aura:iteration items="{!v.productListWrapper}" var="pro" indexVar="index"> <ui:inputSelect aura:id="selectedproductWrapper" class="select-options inline" change="{!c.priceListChange}" value="{!v.priceListValue}" data-selected-Index="{!index}" > </ui:inputSelect> </aura:iteration> controller logic var target = event.target; var dataEle = target.getAttribute("data-selected-Index");
    – Raj_SFDC
    Oct 19, 2016 at 7:51
  • I tried this but it's not working.
    – RaviKant
    Oct 19, 2016 at 8:10
  • 1
    Instead of {!priceList.value} you can pass the varIndex in the text of inputSelectOption, so you will have the selected var index in the priceListValue attribute. This is only if you don't need the text of it. Oct 19, 2016 at 8:21
  • 1
    Did you ever find out a solution for this? I'm facing the same issue. Thanks
    – Jay
    Nov 7, 2017 at 16:53

1 Answer 1

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .