Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs react收音机不';行不通_Reactjs - Fatal编程技术网

Reactjs react收音机不';行不通

Reactjs react收音机不';行不通,reactjs,Reactjs,我创建了一个radio组件,当我创建3个radio时,radio1值为1,radio2值为2,radio2值为3,然后,当我单击radio 1时,console.log(this.state.value)不返回任何内容, 当我单击radio 2时,console.log(this.state.value)返回我1, 当我单击radio 3时,console.log(this.state.value)return me 2, 有什么问题吗 import React, { Component } f

我创建了一个radio组件,当我创建3个radio时,radio1值为1,radio2值为2,radio2值为3,
然后,当我单击radio 1时,
console.log(this.state.value)
不返回任何内容,
当我单击radio 2时,
console.log(this.state.value)
返回我1,
当我单击radio 3时,
console.log(this.state.value)
return me 2, 有什么问题吗

import React, { Component } from 'react';
import { FormGroup } from 'react-bootstrap';
import ContentWrapper from '../../Layout/ContentWrapper';

class Single extends Component {

  constructor(props) {
    super(props);
    this.state = {
      value: props.value
    }
  }

  valueChange = (e) => {
    this.setState({value: e.target.value});
    console.log(this.state.value);
  }

  getSingleChoice = (qItems) => {
    let items = Object.keys(qItems).map((k, index) => {
      let item = qItems[k];
      return (
        <div
          className="radio c-radio"
          id={this.props.id + "_" + k}
          key={this.props.id + "_" + k}
          onChange={e => this.valueChange(e)}>
          <label>
            <input
              type="radio"
              name={"radio" + this.props.id}
              value={item.value}
              defaultChecked={this.state.value == item.value}/>
            <em className="fa fa-circle"></em>{item.label}</label>
        </div>
      );
    });
    return (
      <FormGroup>{items}</FormGroup>
    );
  };

  render() {
    let title = this.props.id + '. ' + this.props.title ';
    return (
      <ContentWrapper>
        <div className="panel panel-default">
          <div className="panel-heading">{title}</div>
          <div className="panel-body">
            {this.getSingleChoice(this.props.options)}
          </div>
        </div>
      </ContentWrapper>
    );
  }
}

export default Single;
import React,{Component}来自'React';
从“react bootstrap”导入{FormGroup};
从“../../Layout/ContentWrapper”导入ContentWrapper;
类单个扩展组件{
建造师(道具){
超级(道具);
此.state={
价值:道具价值
}
}
价值变化=(e)=>{
this.setState({value:e.target.value});
console.log(this.state.value);
}
getSingleChoice=(qItems)=>{
让items=Object.keys(qItems.map)(k,index)=>{
设项=qItems[k];
返回(
此.valueChange(e)}>
{item.label}
);
});
返回(
{items}
);
};
render(){
设title=this.props.id+'.+this.props.title';
返回(
{title}
{this.getSingleChoice(this.props.options)}
);
}
}
导出默认单;
是异步的。如果您想检查它的结果,请使用它的第二个参数并传递回调处理程序,在这里您可以实际看到更改的状态。 例如:

this.setState({value: e.target.value}, () => console.log(this.state.value));
是异步的。如果您想检查它的结果,请使用它的第二个参数并传递回调处理程序,在这里您可以实际看到更改的状态。 例如:

this.setState({value: e.target.value}, () => console.log(this.state.value));

你不应该感到抱歉。只要你愿意改正错误,犯错误是可以的。你不应该后悔。只要你愿意改正,犯错误是可以的。