gpt4 book ai didi

javascript - 如何在 TextInput 中按 'Enter' 调用函数 - React Native

转载 作者:行者123 更新时间:2023-12-02 18:48:36 24 4
gpt4 key购买 nike

我正在尝试制作搜索栏。我希望用户在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com