.get不是一个函数:当我获取js控制器的输入值时,我会遇到错误



我在表的迭代中使用input标记。component.find和get在js控制器中不起作用。获取错误:此页面有错误。您可能只需要刷新它。操作失败:Prefice.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>

控制器:

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 Component时没有记错的话,因为你提供了value={!v.negotiatePrice},所以你可以在控制器中执行component.get('v.negotiatePrice')来获得值。

最新更新