硬件在React和AWS中实现更新突变

时间:2019-03-15 22:20:36

标签: javascript reactjs amazon-dynamodb aws-appsync

我正在尝试在GraphQL的react.js中实现更新突变。但是它似乎对我没有用。这是我的代码

handleChange = name => event => {
    this.setState({
      [name]: event.target.value,
    });
  };

handleSubmit = (e) => {
    this.setState({ open: false });
    var PatientDetails = {
      id: this.props.currentPatient.id,
      Vname: this.state.Vorname || this.props.currentPatient.Vname,
      Nname: this.state.Nachname || this.props.currentPatient.Nname,
      strasse: this.state.Strasse|| this.props.currentPatient.strasse,
      hausnummer: this.state.Hausnr || this.props.currentPatient.hausnummer,
      ort: this.state.Ort || this.props.currentPatient.ort,
      postleitzahl: this.state.Postleitzahl || this.props.currentPatient.postleitzahl
    }
    API.graphql(graphqlOperation(mutations.updatePatient, {input: PatientDetails}));
  }

在这里我尝试返回结果

<h1 id="form-dialog-title">Edit Item: {this.state.currentPatient.Vname}</h1>
          <div className= "patient" 
          open={this.state.open}
          onClose={this.handleClose} >
          <input
              name='Vorname'
              placeholder={this.props.currentPatient.Vname}
              onChange={this.handleChange('Vorname')}
              className='Patient-header'
           />
           <input
    name='Nachname'
    placeholder={this.props.currentPatient.Nname}
    onChange={this.handleChange('Nachname')}
    className='Patient-header'
  /> <input
  name='Strasse'
  placeholder={this.props.currentPatient.strasse}
  onChange={this.handleChange('Strasse')}
  className='Patient-header'
/>
 <input
    name='Hausnr'
    placeholder={this.props.currentPatient.hausnummer}
    onChange={this.handleChange('Hausnr')}
    className='Patient-header'
  />
   <input
    name='Ort'
    placeholder={this.props.currentPatient.ort}
    onChange={this.handleChange('Ort')}
    className='Patient-header'
  />
   <input
    name='Postleitzahl'
    placeholder={this.props.currentPatient.postleitzahl}
    onChange={this.handleChange('Postleitzahl')}
    className='Patient-header'
  />

</div>
<button
  className= "Patient"
  onClick={this.handleSubmit}

>EditPatient</button>

我认为应该有一个更好的方法来执行此操作,但我似乎无法弄清楚。一个帮助将不胜感激。谢谢!

0 个答案:

没有答案