0

Component:

    <aura:iteration items="{!v.QliList}" var="Qli" indexVar="sNo">      
               <tr>
                    <td><div class="slds-truncate">{!sNo+1}</div></td>
                    <td><div class="slds-truncate">{!Qli.Name}</div></td>
                    <td><div class="slds-truncate">{!Qli.Description__c}</div></td>
                   <td><div class="slds-truncate">{!Qli.Family__c}</div></td>
                   <td><div class="slds-truncate"><ui:inputText aura:id="dynamicResult" class="pnsuggestion" value="{!Qli.Part_number_Suggestion__c}"/></div></td>
                   <!--<td><div class="slds-truncate">{!Qli.PN_Suggestion__c}</div></td>-->
                    <td><div class="slds-truncate"></div>
                    <lightning:button type="button" onclick="{!c.UpdatePnsuggestion}"   name="CMM Tooling and Accessories" label="{!sNo}">CMM Tooling and Accessories</lightning:button>
<lightning:button type="button" onclick="{!c.UpdatePnsuggestion}"  name="CMM Prewired" label="{!sNo}">CMM Prewired</lightning:button>
 </td>
                </tr>
          </aura:iteration>

Js controller:

 UpdatePnsuggestion: function(component,event,helper){
   var va= event.getSource().get("v.name");
   var indexnumber= event.getSource().get("v.label");
  console.log(indexnumber);
    component.set("v.QliList.Part_number_Suggestion__c", va);  
},  

I want to pass the button value to inputtext field {!Qli.Part_number_Suggestion__c}

In iteration n number of record when I click on a button it is copying the value to all records. But in my case, I would like to copy value only to the current row. Please Help me on this.

I am getting row number as well.

1

You are getting all the value because:-

You button markup is :- <lightning:button type="button" onclick="{!c.UpdatePnsuggestion}" name="CMM Prewired" label="{!sNo}">CMM Prewired</lightning:button> where name attribute has hardcoded value. i.e. CMM Prewired . The name is same for all the rows and hence giving you all the rows.

You need to assign a dynamic value from iteration variable like:- {!Qli.Name}

So you button markup will be:-

<lightning:button type="button" onclick="{!c.UpdatePnsuggestion}"  name="{!Qli.Name}" label="{!sNo}">CMM Prewired</lightning:button>

Then var va= event.getSource().get("v.name"); will give you selected name only.

1

I think the easiest solution is to set the name of your button to your indexVar (unforunately, aura:id cannot be dynamically set in an aura:iteration). This will allow you to get the index in your controller using: event.getSource().get("v.name"). You can then update the appropriate row in QliList based on that index.

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.