繁体   English   中英

.get 不是 function:当我获取 js controller 的输入值时,我遇到了错误

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

我在表的迭代中使用输入标签。 component.find 和 get 在 js controller 中不起作用。 收到错误:此页面有错误。 您可能只需要刷新它。 操作失败:nPrice.get 不是函数] 失败描述符:{c:SP_TCOSandboxLicense$controller$CalculatePrice}

零件:

    <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); 
   }

基本上可以直接使用event ,效率会更高: event.target.value

另外,如果我在编写 Aura 组件时没记错的话,因为您提供了value={.v.negotiatePrice} ,您可以在 controller 中执行component.get('v.negotiatePrice')来获取值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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