【问题标题】:OnChange event.target.value doesnt get the value in reactOnChange event.target.value 没有得到反应中的值
【发布时间】:2020-05-13 07:21:01
【问题描述】:

所以我有 2 个单选按钮,当他们进行更改时,我想从进行更改的单选按钮中获取值。

这是我迄今为止尝试过的:

handleValue = (event) => {
    this.setState({
      chargetype: event.target.value,
    });
  };

  <RadioGroup onChange={this.handleValue} horizontal>
            <RadioButton value="fixed">Fixed</RadioButton>
            <RadioButton value="people" >People</RadioButton>
</RadioGroup>

但由于某种原因,它没有得到 RadioButton 的值。

有谁知道正确的做法吗?

【问题讨论】:

标签: reactjs radio-button onchange react-radio-buttons


【解决方案1】:

RadioGroup 上的onChange 事件直接为您提供价值,而不是事件

你可以这样写

handleValue = (value) => {
    this.setState({
      chargetype: value,
    });
  };

  <RadioGroup onChange={this.handleValue} horizontal>
            <RadioButton value="fixed">Fixed</RadioButton>
            <RadioButton value="people" >People</RadioButton>
</RadioGroup>

以上推论是基于library's official example

Working demo

【讨论】:

    猜你喜欢
    • 2021-08-24
    • 2021-06-07
    • 2019-02-19
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2020-09-28
    相关资源
    最近更新 更多