我正在尝试处理我的表单中的更改.我有标题,描述和类别.
第一个输入(标题) - >无法在字段中输入.
第二个输入(描述) - >能够输入字段但结果未定义.
第三个输入(类别DDL) - >无法更改所选类别,但默认选择在我的alret中输出为'drink';
问题:
AddDeal正在更改类型文本的受控输入以使其不受控制.输入元素不应从受控切换到不受控制(反之亦然).决定在组件的使用寿命期间使用受控或不受控制的输入元素.
我已经在这里查看了受控组件的反应文件,但发现它很难理解,因为我是新手.
https://facebook.github.io/react/docs/forms.html#controlled-components
这是我的代码 AddDeal.js
export default class AddDeal extends React.Component {
  constructor(props) {
    super(props);
    // Set the state
    this.state = {
      title: '',
      description: '',
      category: 'technology'
    };
    this.onSubmit = this.onSubmit.bind(this);
    this.handleChange = this.handleChange.bind(this);
  }
  onSubmit(e) {
    e.preventDefault();
    alert('Title is: ' + this.state.title + 'Description is: ' + this.state.description + 'Category is: ' + this.state.category);
  }
  handleChange(e) {
    this.setState({
      title: e.target.title,
      description: e.target.description,
      category: e.target.value
    });
  }
  render() …