简体   繁体   English

如何在组件中获取材料 ui 选择器的值?

[英]How to get material ui pickers value in component?

On Selecting the date from the date picker how to get the value in component从日期选择器中选择日期如何获取组件中的值

Demo Link : https://material-ui.com/demos/pickers/演示链接https : //material-ui.com/demos/pickers/

1st example第一个例子

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';

const styles = theme => ({
  container: {
    display: 'flex',
    flexWrap: 'wrap',
  },
  textField: {
    marginLeft: theme.spacing.unit,
    marginRight: theme.spacing.unit,
    width: 200,
  },
});

function DatePickers(props) {
  const { classes } = props;

  return (
    <form className={classes.container} noValidate>
      <TextField
        id="date"
        label="Birthday"
        type="date"
        defaultValue="2017-05-24"
        className={classes.textField}
        InputLabelProps={{
          shrink: true,
        }}
      />
    </form>
  );
}

DatePickers.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(DatePickers);

Thanks in advance提前致谢

refer the api Doc from here: https://material-ui.com/api/text-field/从这里参考 api 文档: https : //material-ui.com/api/text-field/

export default class App extends PureComponent {
  state = {
    value: ""
  };

  render() {
    const { value } = this.state;

    return (
      <div>
        <TextField
          id="date"
          label="Birthday"
          type="date"
          defaultValue="2017-05-24"
          InputLabelProps={{
            shrink: true
          }}
          onChange={event => {
            this.setState({ value: event.target.value });
          }}
        />
        {value}
      </div>
    );
  }
}

and example from here: https://codesandbox.io/s/3rp5zl971和这里的例子: https : //codesandbox.io/s/3rp5zl971

hope this will help you希望能帮到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM