-1

I want to set the value based on key,using aura:id

Component:

{!mapKey.key}

                                            <label class="slds-checkbox slds-box" style="width:100%;">
                                                <ui:inputCheckbox text="{!mapValue}"
                                                                  value="{!mapValue.isChecked}"
                                                                  aura:id="{!index}"

                                                                  change="{!c.selectSubProcess}"/>
                                                <span class="slds-checkbox--faux" /> &nbsp;
                                                <span class="slds-form-element__label" style="font-size: 15px;">{!mapValue.subprocessName}</span>
                                                <br/> </label>
                                            <aura:if isTrue="{!mapValue.isChecked}">
                                                <!-- tt<lightning:input name="input2" label="we" value="{!v.O2CWeightage}" class="field"/>-->

                                                <div class="slds-grid slds-gutters">
                                                    <span  class="slds-col">

                                                        <ui:inputText aura:id="{!mapValue.key}" label="Weightage:" 
                                                                      class="field"
                                                                      labelClass="slds-form-element__label"
                                                                      value="{!mapValue.Weightage}"
                                                                      required="false"/>
                                                 <aura:iteration items="{!v.SubProcessMap}" var="cus" indexVar="key">

                                                     <aura:if isTrue="{!cus.key==mapValue.key}">
                                                      {!cus.value}
                                                     </aura:if>
                                                        </aura:iteration>
                                                    </span><span  class="slds-col">
                                                    <img src="{!$Resource.Edit_Icon}" onclick="{!c.editO2C}"/>
                                                    </span>
                                                </div>
                                            </aura:if>


                                        </aura:iteration>

Controller.js:

for(var key in countStrings){
            console.log(key);
            SubProcessMap.push({key: key, value: 100/countStrings[key]});  
        }
        component.set("v.SubProcessMap",SubProcessMap);
        console.log('SubProcessMap==>'+JSON.stringify(SubProcessMap));
        //Setting of Value
        var weightage=[];
        weightage= component.find("selectedprocesskeys.key");

My map values are:

SubProcessMap==>[{"key":"Vendor Master","value":25},{"key":"Customer Master","value":50}]

ANd,now in component i want to set aura:id as {!mapValue.key},bcoz it should key as Vendor Master,customer master......

and based on key,value should be kept in input box

1

In lightning component, you cannot assign aura ID a dynamic value. Check this post for more information.

You can leverage HTML Data attributes in iteration to keep dynamic IDs or Keys for identification of particular data in the controller using the event from where the element was triggered.

Aura Component Snippet

<aura:iteration items="{!v.SearchResults}" var="sr"  indexvar="index">
    <tr onclick="{!c.selected}" data-record="{!sr.Id}">   
    <td><ui:outputText value="{!sr.Id}"/></td>  

Controller Snippet

selected: function(cmp,event,helper){
   var selectedItem = event.currentTarget;
   var recId = selectedItem.dataset.record;
| improve this answer | |

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.