繁体   English   中英

从数组中的值分配表单值

[英]Assigning form value from values within an array

我有一个表格,每行旁边都有一个编辑按钮。 我将人员ID发送到表单组件,并使用ID从数据库中获取其数据。 我将其分配给患者。 然后,我想使用数据自动填写表格。

这是文件的顶部。

class PtEditForm extends React.Component {
  constructor(props) {
    super(props);

    //console.log(this.props.location.search);
    const query = queryString.parse(this.props.location.search);
    console.log(query.patientId);

    this.state = {
      ptId: query.patientId || null,
      patient: null
    };

这是我在登录时确认有效的提取。

  getPatient() {
    fetch("https://localhost:5001/api/PtEditPg/" + this.state.ptId)
      .then(response => response.json())
      .then(data => this.setState({ patient: data }));
  }

这是显示我尝试过的形式之一

              <label htmlFor="firstName">First Name</label>
              <input
                type="Name"
                className="form-control"
                id="firstName"
                name="firstName"
                placeholder="First Name"
                value={this.state.patient.firstName}
                onChange={this.handleChange}
              />

我终于弄明白了。 我认为对象是数组吗?

这是有效的

this.state.patient[0].firstName

暂无
暂无

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

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