1

我是 ReactJs 和 react-materialize 的新手。我借助组件中的 react-materialize 创建了两个输入元素类型 Radio。两者都在 DOM 中呈现。

我单击第一个单选选项被选中并触发 onChange 事件。单击第二个选项后,第一次单击时未选择,但在第二次单击时工作正常。单击任何选项后,两者都不会触发事件。

“反应”:“^16.5.2” “反应物化”:“^2.4.8”,

这个问题与此解决方案相同并尝试过,但无法正常工作https://github.com/react-materialize/react-materialize/issues/422

import React, {Component} from 'react'; 
import {Input} from 'react-materialize';
class Section extends Component {
    render() {
         return (
           <div className="row">
                {
                   this
                    .props
                    .options
                    .map((option, index) => (
                        <div key={index} className="col s6">
                            <Input
                                type="radio"
                                name="report"
                                className="with-gap"
                                value={option.value}
                                checked = {this.props.selected}
                                key={index}
                                onChange={(e)=>console.log(e.target.value)}
                                label={option.label}/>
                        </div>
                    ))
            }
        </div>
    );
}

}

我希望在第一次单击时应选择两个单选选项的输出,并在所有单击时调用 onChange。请纠正我犯了什么错误。

4

0 回答 0