• 下拉选中


    import TextField from '@material-ui/core/TextField';
    import MenuItem from '@material-ui/core/MenuItem';
    
    const currencies = [
        {
          value: 'USD',
          label: '$',
        },
        {
          value: 'EUR',
          label: '€',
        },
        {
          value: 'BTC',
          label: '฿',
        },
        {
          value: 'JPY',
          label: '¥',
        },
      ];
    
    /**
     * @param error 是否是错误
     * @param fullWidth 是否全部宽度
     * @param placeholder 说明文字
     * @param remark 追加说明
     * @param required 是否必填
     * @param type 类型
     * @param name 属性值.
     * @param onChange 更新处理方法
     */
    class JSelect extends React.Component {
    
        constructor(props){
            super(props);
            this.state={
                value:'',
            }
        }
    
        static getDerivedStateFromProps(nextProps) {
            if (nextProps && null != nextProps && undefined != nextProps.onChange) {
                return {
                    value : nextProps.value || ''
                }
            }
            return null;
        }
    
        onChange = (evt)=>{
            const fix =evt.target.value;
            const {onChange,data,name} = this.props;
            if(onChange){
                const item = data.filter(v=>v.value == fix)[0];
                onChange(item,name);
            }else{
                this.setState({value:fix});
            }
        }
    
        render() {
            const { data=currencies, error, fullWidth = true, placeholder = 'placeholder',
              required=false,disabled=false,
                remark,width=180} = this.props;
            const {value} = this.state;
            return  (<TextField
                select
                error={error}
                label={placeholder}
                fullWidth={fullWidth}
                size="small"
                value={value}
                onChange={this.onChange}
                helperText={remark}
                required={required}
                variant="outlined"
                disabled={disabled}
                style={{minWidth:width}}
              >
                {data.map((option) => (
                  <MenuItem key={option.value} value={option.value}>
                    {option.label}
                  </MenuItem>
                ))}
              </TextField>);
        }
    }
    
    export default JSelect;
    import TextField from '@material-ui/core/TextField';
    import MenuItem from '@material-ui/core/MenuItem';
    
    const currencies = [
        {
          value: 'USD',
          label: '$',
        },
        {
          value: 'EUR',
          label: '€',
        },
        {
          value: 'BTC',
          label: '฿',
        },
        {
          value: 'JPY',
          label: '¥',
        },
      ];
    
    /**
     * @param error 是否是错误
     * @param fullWidth 是否全部宽度
     * @param placeholder 说明文字
     * @param remark 追加说明
     * @param required 是否必填
     * @param type 类型
     * @param name 属性值.
     * @param onChange 更新处理方法
     */
    class JSelect extends React.Component {
    
        constructor(props){
            super(props);
            this.state={
                value:'',
            }
        }
    
        static getDerivedStateFromProps(nextProps) {
            if (nextProps && null != nextProps && undefined != nextProps.onChange) {
                return {
                    value : nextProps.value || ''
                }
            }
            return null;
        }
    
        onChange = (evt)=>{
            const fix =evt.target.value;
            const {onChange,data,name} = this.props;
            if(onChange){
                const item = data.filter(v=>v.value == fix)[0];
                onChange(item,name);
            }else{
                this.setState({value:fix});
            }
        }
    
        render() {
            const { data=currencies, error, fullWidth = true, placeholder = 'placeholder',
              required=false,disabled=false,
                remark,width=180} = this.props;
            const {value} = this.state;
            return  (<TextField
                select
                error={error}
                label={placeholder}
                fullWidth={fullWidth}
                size="small"
                value={value}
                onChange={this.onChange}
                helperText={remark}
                required={required}
                variant="outlined"
                disabled={disabled}
                style={{minWidth:width}}
              >
                {data.map((option) => (
                  <MenuItem key={option.value} value={option.value}>
                    {option.label}
                  </MenuItem>
                ))}
              </TextField>);
        }
    }
    
    export default JSelect;

    import TextField from '@material-ui/core/TextField';
    import MenuItem from '@material-ui/core/MenuItem';

    const currencies = [
    {
    value: 'USD',
    label: '$',
    },
    {
    value: 'EUR',
    label: '€',
    },
    {
    value: 'BTC',
    label: '฿',
    },
    {
    value: 'JPY',
    label: '¥',
    },
    ];

    /**
    * @paramerror 是否是错误
    * @paramfullWidth 是否全部宽度
    * @paramplaceholder 说明文字
    * @paramremark 追加说明
    * @paramrequired 是否必填
    * @paramtype 类型
    * @paramname 属性值.
    * @paramonChange 更新处理方法
    */
    class JSelect extends React.Component {

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

    static getDerivedStateFromProps(nextProps) {
    if (nextProps && null != nextProps && undefined != nextProps.onChange) {
    return {
    value : nextProps.value || ''
    }
    }
    return null;
    }

    onChange = (evt)=>{
    const fix =evt.target.value;
    const {onChange,data,name} = this.props;
    if(onChange){
    const item = data.filter(v=>v.value == fix)[0];
    onChange(item,name);
    }else{
    this.setState({value:fix});
    }
    }

    render() {
    const { data=currencies, error, fullWidth = true, placeholder = 'placeholder',
    required=false,disabled=false,
    remark,width=180} = this.props;
    const {value} = this.state;
    return (<TextField
    select
    error={error}
    label={placeholder}
    fullWidth={fullWidth}
    size="small"
    value={value}
    onChange={this.onChange}
    helperText={remark}
    required={required}
    variant="outlined"
    disabled={disabled}
    style={{minWidth:width}}
    >
    {data.map((option) => (
    <MenuItem key={option.value} value={option.value}>
    {option.label}
    </MenuItem>
    ))}
    </TextField>);
    }
    }

    export default JSelect;
    未闻花名
  • 相关阅读:
    Spring 09 : AOP实例
    Spring08 AOP概念
    Spring 07 : 动态代理
    Spring06 Spring+Junit
    Spring05 : 基于注解的IOC
    Spring03 : 依赖注入
    jupyter修改python核(使用不同的python虚拟环境)
    线性代数的本质——引入几何视角
    图像的去雾与加雾
    从MATLAB看一个IDE应该具有的素质
  • 原文地址:https://www.cnblogs.com/duokexiao/p/13808545.html
Copyright © 2020-2023  润新知