我正在尝试制作搜索栏。我希望用户在 TextInput
中键入内容,当用户按下“Enter”时,我想调用我的函数。
<TextInput
//here when user press enter call function()
style={styles.searchStyle}
allowFontScaling={false}
placeholder="Search"
onChangeText={(val) => {setSearch(val)}}
/>
我尝试了 onSubmitEditing
但它不起作用。
最佳答案
import React, { Component } from 'react' import {TextInput} from 'react-native'
const Trial =()=>{
const onSubmitted=()=>{
console.log('Submitted')
}
return(
<TextInput
//here when user press enter call function()
// style={styles.searchStyle}
allowFontScaling={false}
placeholder="Search"
onSubmitEditing={()=>onSubmitted()}
/>
)
}
export default Trial
onSubmitEditing 运行良好,希望对您有所帮助
关于javascript - 如何在 TextInput 中按 'Enter' 调用函数 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67098132/