【问题标题】:how to set state of textinput react如何设置文本输入反应的状态
【发布时间】:2018-12-24 04:29:25
【问题描述】:

我刚学react Native,为什么我按下按钮时editable没有变为true?

class App extends React.Component {
  state = { isWrong: false };

  render() {
    return (
      <div>
        <TextInput editable={this.state.isWrong} />
        <Button
          onPress={() => {
            this.setState.isWrong = true;
          }}
        />
      </div>
    );
  }
}

【问题讨论】:

  • this.setState({ isWrong: true })

标签: javascript reactjs react-native textinput


【解决方案1】:

setState 是一个函数

const new_values = { isWrong: true };
this.setState(new_values);

【讨论】:

    【解决方案2】:

    这样的事情应该会有所帮助:

    <TextInput editable={this.state.isWrong} />
    <Button
      onPress={()=> this.setState({ isWrong: true })} >
    </Button>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-25
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 2020-01-24
      • 2017-05-08
      相关资源
      最近更新 更多