1、定义input接入输入框输入内容,定义绑定的方法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12constructor(props) { super(props); this.state = { input: '', }; //下面两条语句将两个回调函数和成员方法绑定 this.handleInput = this.handleInput.bind(this); } //处理输入的消息 handleInput(text) { this.setState({input: text}); }
2、编写TextInput
复制代码
1
2
3
4
5
6<TextInput style={styles.inputView} placeholder="请在此输入留言内容" placeholderTextColor={'#b3b3b3'} value={this.state.input} onChangeText={newText => this.handleInput(newText)}></TextInput>
这里重点是
复制代码
1value={this.state.input}
这样TextInput的输入框就和this.state.input绑定了,要情况TextInput输入框,只需要进行以下操作即可
复制代码
1this.setState({input: ''});
只需要以上两步,即可完成TextInput跟this.state.input的绑定,从而对TextInput输入框进行清空
最后
以上就是俊秀跳跳糖最近收集整理的关于React-native输入框如何绑定清除数据的全部内容,更多相关React-native输入框如何绑定清除数据内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复