简体   繁体   中英

.get is not a function: When i am getting the value of the input to js controller i am facing the error

I am using input tag inside the iteration to the table. component.find and get are not working in js controller. Getting the error: This page has an error. You might just need to refresh it. Action failed:nPrice.get is not a function] Failing descriptor: {c:SP_TCOSandboxLicense$controller$CalculatePrice}

Component:

    <aura:attribute name="negotiatePrice" type="Integer" />

    <table class="slds-table slds-table--bordered slds-table--cell-buffer">
      <tbody>
        <aura:iteration items="{!v.userList}" var="con" aura:id="usrLst">
          <tr>
             <th scope="row">
                <div class="slds-truncate" title="{!con.Name}">
                    {!con.Name} 
                </div>
             </th>
             <th scope="row">
               <div aura:id="usrLic" class="slds-truncate" title="{!con.TotalLicenses}">{!con.TotalLicenses}</div>
             </th>
             <th scope="row"> 
                <aura:iteration items="{!v.costList}" var="cst">                                     
                  <aura:if isTrue="{!con.Name == cst.Name}">                                   
                    <div class="slds-truncate" title="{!cst.License_Price_Per_Month__c}">{!cst.License_Price_Per_Month__c}</div>
                  </aura:if>
                </aura:iteration>
             </th>
                                        
             <th scope="row" >
               <div class="slds-truncate">
                  <input type="number" aura:id="myAtt" placeholder="Enter Negotiated Price" class="slds-input inputField"  value="{v.negotiatePrice}" onchange="{!c.CalculatePrice}" /> 
                                   
               </div>
             </th>
                                       
           </tr>   
         </aura:iteration>
     </tbody>
</table>

Controller:

    CalculatePrice : function(component, event, helper) {  
            
            alert('Calculate');
            var nPrice = component.find("myAtt");
            var negotiatePrice = nPrice.get("v.value");
            alert('negotiatePrice'+negotiatePrice); 
   }

You can basically use the event directly, it will be more efficient: event.target.value

Also if I remember correctly from the time I was writing Aura Component, because you provided value={.v.negotiatePrice} you can do component.get('v.negotiatePrice') in your controller to get the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM