• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

React-native输入框绑定清除数据

武飞扬头像
晒干的老咸鱼
帮助1

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

  1.  
    constructor(props) {
  2.  
    super(props);
  3.  
    this.state = {
  4.  
    input: '',
  5.  
    };
  6.  
    //下面两条语句将两个回调函数和成员方法绑定
  7.  
    this.handleInput = this.handleInput.bind(this);
  8.  
    }
  9.  
     
  10.  
     
  11.  
    //处理输入的消息
  12.  
    handleInput(text) {
  13.  
    this.setState({input: text});
  14.  
    }

2、编写TextInput

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

这里重点是

value={this.state.input}

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

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

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgcbafj
系列文章
更多 icon
同类精品
更多 icon
继续加载