import * as React from 'react'; import './dataSource.scss' interface Props { dataSourceChange:Function, options:Array, selected:number } export default class DataSource extends React.Component { state = { show:false, oringin:false } changeShow = () => { // setTimeout( () => { findDOMNode(this.refs.dataSource).focus() }, 0 ) this.setState({ show: !this.state.show }) } componentDidMount(){ document.addEventListener('click', this.hideSelectComponent, false); } componentWillUnmount() { document.removeEventListener('click', this.hideSelectComponent, false); } hideSelectComponent = () =>{ const {oringin} = this.state; this.setState({ oringin:false }); !oringin && this.setState({show: false}) } changeSelect = (index:number) => { this.props.dataSourceChange(index) this.setState({ show : !this.state.show }) } blurItems = () => { this.setState( { show : false } ) } render(){ const { show } = this.state; const { options, selected } = this.props; return
{this.setState({oringin:true})}}> 来源:
{ options[selected] }
    { options.map( ( data, index ) => { return
  • { this.changeSelect(index) } }> { data }
  • } ) }
} }