【问题标题】:Detect device's enter key IonSearchBar检测设备的输入键 IonSearchBar
【发布时间】:2023-03-07 08:11:01
【问题描述】:

我正在寻找的是在按下设备的回车键时运行搜索功能,但我做不到。如果使用 onIonChange 我可以过滤单词

需要使用什么事件来检测设备上的输入? onIonInput 不能检测回车键

const Search = () =>{
  //do something
   }   
const Words = (value:any) =>{
  //do something
   }   
     return(
    <>
      <IonSearchbar debounce={500} type="text" onIonChange={e => {Words(e.detail.value!)}} onIonInput={ Search} ></IonSearchbar>
    </>
     )
   };

【问题讨论】:

    标签: reactjs ionic-framework


    【解决方案1】:

    您可以使用onKeyPressevent.key 来监听回车键。

    const keypress = (event) => {
      if(event.key === 'Enter') {
        // Run search function
      }
    }  
         
    return(
      <>
       <IonSearchbar onKeyPress={keypress}></IonSearchbar>
      </>
    )};
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多