• 下拉选中


    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;
    未闻花名
  • 相关阅读:
    NConsoler 介绍
    HOWTO:批量删除存储过程和表
    HOWTO:使ASP.NET网站Forms验证可以指定多个登录页面
    [架构模式实践]如何不让第三方服务/组件的故障阻碍开发和测试进度
    GDI+学习笔记
    脚印: SD2C 2009 参会小记(非技术篇)
    Expression Web使用问题,相关资源及今日阅读
    HOWTO:FirePHP乱码问题解决
    [ECSHOP挖寶]用戶注銷過程
    励志好文
  • 原文地址:https://www.cnblogs.com/duokexiao/p/13808545.html
Copyright © 2020-2023  润新知