gpt4 book ai didi

reactjs - 在 native react 中处理具有 onChangeText 事件属性的对象

转载 作者:行者123 更新时间:2023-12-03 14:20:15 28 4
gpt4 key购买 nike

我是 React Native 的新手,不知道如何处理当前的情况,并且我已经花了很多时间寻找解决方案。我有以下构造函数:

constructor (props) {
super(props);
this.state = {
newNote: { title: '', description: '', dateToRead: null },
modalVisible: false
};
}

如何保存 TextInput 中 onChangeText 事件的值? React Native 中的属性处理是否正确?

最佳答案

处理 TextInput 数据的两种方法

<TextInput
onChange={(event) =>
this.setState({newNote: {...this.state.newNote,
title: event.nativeEvent.text}}
)}
value={this.state.newNote.title}
/>

<TextInput
onChangeText={(text) =>
this.setState({newNote: {...this.state.newNote,description: text}}
)}
value={this.state.newNote.description}
/>

关于reactjs - 在 native react 中处理具有 onChangeText 事件属性的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44081485/

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