我是靠谱客的博主 俊秀跳跳糖,这篇文章主要介绍React-native输入框如何绑定清除数据,现在分享给大家,希望可以做个参考。

1、定义input接入输入框输入内容,定义绑定的方法

constructor(props) {
super(props);
this.state = {
input: '',
};
//下面两条语句将两个回调函数和成员方法绑定
this.handleInput = this.handleInput.bind(this);
}
//处理输入的消息
handleInput(text) {
this.setState({input: text});
}

2、编写TextInput

<TextInput
style={styles.inputView}
placeholder="请在此输入留言内容"
placeholderTextColor={'#b3b3b3'}
value={this.state.input}
onChangeText={newText => this.handleInput(newText)}></TextInput>

这里重点是

value={this.state.input}

 这样TextInput的输入框就和this.state.input绑定了,要情况TextInput输入框,只需要进行以下操作即可

this.setState({input: ''});

只需要以上两步,即可完成TextInput跟this.state.input的绑定,从而对TextInput输入框进行清空 

最后

以上就是俊秀跳跳糖最近收集整理的关于React-native输入框如何绑定清除数据的全部内容,更多相关React-native输入框如何绑定清除数据内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部