import React, { Component } from 'react'; import './index.less'; import RadioItem from '../RadioItem'; export default class Answer extends Component { constructor(props) { super(props); const single = []; const double = []; switch (props.type) { case 'single': for (let i = 0; i < props.list.length; i += 1) { single.push(false); } break; case 'double': for (let i = 0; i < props.list.length; i += 1) { double.push([false, false]); } break; default: break; } this.state = { single, double }; } onChangeSingle(index) { const { single } = this.state; for (let i = 0; i < single.length; i += 1) { single[i] = false; } single[index] = true; this.setState({ single }); this.onChange(single); } onChangeDouble(index, column) { const { direction } = this.props; let { double } = this.state; switch (direction) { case 'landscape': double[index] = double[index].map(() => false); break; case 'portrait': double = double.map(row => { row[column] = false; return row; }); break; default: break; } double[index][column] = true; this.setState({ double }); this.onChange(double); } onChange(value) { const { onChange } = this.props; if (onChange) onChange(value); } render() { return
{first} | {second} | |
---|---|---|
|
|
{item} |