我有以下代码在Chrome和我目前为止测试过的所有其他浏览器中运行得非常好:
<div class="slds-grid slds-wrap">
<div class="slds-col slds-size--1-of-1 slds-small-size--3-of-4 slds-medium-size--2-of-3 " onkeyup="{!c.enterClicked}">
<div class="inputWrapper searchInpFastlane" >
<c:input aura:id="PortalFastlaneSearchBar" value="{!v.searchInput}" type="text" placeholder="{!v.placeholderText}" useIcons="false" class="noMargins heightXL searchInpFastlane3" labelClass="hidden"/>
</div>
</div>
<div class="slds-col slds-size--1-of-1 slds-small-size--1-of-4 slds-medium-size--1-of-3 searchBtnPad">
<div class="buttonWrapper searchBtn">
<c:button buttonLabel="Search" onclick="{!c.searchButtonClicked}" buttonClass="valmetPrimaryButton" showImage="false"/>
</div>
</div>
</div>
我的控制器看起来像这样:
enterClicked : function(component, event, helper)
{
console.log("1");
if(event.keyCode && event.keyCode === 13)
{
console.log("2");
try
{
console.log("3");
console.log(component.get("v.searchInput"));
helper.search(component, helper);
}
catch(e)
{
console.log("4");
Console.log(e);
}
}
},
searchButtonClicked : function(component, event, helper)
{
try
{
console.log(component.get("v.searchInput"));
helper.search(component, helper);
}
catch(e)
{
Console.log(e);
}
}
我只是不知道为什么console.log(component.get("v.searchInput"));
似乎没有显示任何内容,而是在点击输入时显示未定义。
通过单击按钮
调用searchButtonClicked时,它可以正常工作答案 0 :(得分:0)
通过在try语句`document.getElementById('searchKeyword')中添加这行代码来设法解决它.fluti(); ,基本上aura属性似乎没有更新,绑定除非你从输入中放松了焦点,所以我正在做什么我以编程方式从输入中失去焦点,这才有效!
我的代码变得像:
enterClicked : function(component, event, helper)
{
if(event.keyCode && event.keyCode === 13)
{
try
{
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
{
document.getElementById('searchKeyword').blur();
helper.search(component, helper);
}
else // If another browser, return 0
{
helper.search(component, helper);
}
}
catch(e)
{
Console.log(e);
}
}
},