1

I have a lightning component where I dynamically generate some columns and some input fields. I have a String Array as attribute. How do I get the index of the array to pass the value. I tried below but this gives me an expression error.

Attribute

<aura:attribute name="searchKeywordArr" type="String[]" description="store search input"/>

Iteration

 <aura:iteration items="{!v.colData}" var="obj" indexVar="index">
                            <td role="gridcell">
                                <lightning:input 
                                                 value="{!v.searchKeywordArr[v.indexVar]}"
                                                 required="false"
                                                 placeholder="{!obj.label + '...'}"
                                                 aura:id="{!obj.Id}"
                                                 label="{!obj.label}"
                                                 variant="label-hidden"/>
                                
                            </td>
                        </aura:iteration>
2
  • @AlbaRivas I found the solution and posted this as an answer please remove your link because this is misleading. Thanks in advance. – Thomas Feb 12 at 16:22
  • I was trying to give a solution to the value="{!v.searchKeywordArr[v.indexVar]}" bit which is what I understood that you had problems with, but ok, removed. – Alba Rivas Feb 12 at 16:54
0

For anyone looking for an anwer. The following works

Component:

  <aura:iteration items="{!v.colData}" var="obj" indexVar="index">
        <lightning:input type="text" name="{!index}" value="{!obj}" label="Lightning Input" onchange="{!c.update}"/>
     </aura:iteration>

Javascriptcontroller:

update : function(component,event){
        var index = event.getSource().get('v.name');
            alert('index' + index);  
        var value = event.getSource().get('v.value');
              alert('value' + value);  
    }

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.