/** * Crawler simulation module * @author Hai Zheng */ class CrawlerSimulate extends React.Component { constructor(props) { super(props); this.state = { list: props.list, }; this.handleInputChange = this.handleInputChange.bind(this); this.delRow = this.delRow.bind(this); this.addNew = this.addNew.bind(this); } handleInputChange(e, index) { const target = e.target; const value = target.type === 'checkbox' ? target.checked : target.value; const list = this.state.list; list[index][target.dataset.type] = value; this.setState({ list: list, }); } delRow(index) { const data = this.state.list; data.splice(index, 1); this.setState({ list: data }); } addNew() { const list = this.state.list; list.push({ name: '', vals: '' }); this.setState({ list: list }); } render() { return ( {this.state.list.map((item, i) => ( ))}

); } } // { name: '', vals: '' } class SimulationBlock extends React.Component { constructor(props) { super(props); this.handleInputChange = this.handleInputChange.bind(this); this.delRow = this.delRow.bind(this); } handleInputChange(e) { this.props.handleInputChange(e, this.props.index); } delRow() { this.props.delRow(this.props.index); } render() { const item = this.props.item; return (