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

标签 javascript node.js react-native react-native-ios

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

相关文章:

javascript - 引号内的 jquery 变量名

node.js - `fs.appendFile()` 的原子性保证是什么?

javascript - 为什么可枚举: false not cascade to inherited classes in TypeScript?

javascript - React 和 React Native 中导入路径差异

reactjs - 什么是 React Native Web?

javascript - 如何修复您应该只在 IOS 的应用程序中显式渲染一个导航器

javascript - 为什么clearInterval()不起作用?

javascript - 尝试更改 Textarea 的值(使用 Skulpt)

javascript - 确定集合并删除 Angular 中的一项特定项目

javascript - Node.js html查询和解析