Hallo Ich versuche, den Wert meiner Eingabe in das Formular an meine Abruffunktion aufrufen, aber es kann es nicht lesen, bitte helfen Sie mir ... Ich würde tun eine Abruf Post, so dass ich es in meinem Tisch legen kann ...Wie kann ich den Eingangswert auf meiner Funktion anrufen ReactJs
meine Funktion ist wie
handleSubmit() {
debugger
function createNewProfile(profile) {
const formData = new FormData();
formData.append('Employee_Name', profile.Employee_Name);
formData.append('Address', profile.Address);
formData.append('Department', profile.Department);
return fetch('http://localhost:5118/api/employeedetails/PostEmployeeDetail/', {
method: 'POST',
body: formData
}).then(response => response.json())
}
createNewProfile(profile)
.then((json) => {
// handle success
}
).catch(error => error);
}
und dies ist meine Form, wo ich meine
<form onSubmit={this.handleSubmit}>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td>
<input type="text"
name="Employee_Name"
className="EmployeeDetails"
value={this.props.Employee_Name}/>
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text"
name="Address"
className="EmployeeDetails"
value={this.props.Address}
onChange={this.props.handleChange}/>
</td>
</tr>
<tr>
<td>Department</td>
<td>
<input type="text"
name={this.props.Department}
className="EmployeeDetails"
value={this.props.Department}/>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<input type="submit" className="btn btn-info" onClick={ this.handleSubmit} value=" Add Employee"/>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
im Versuch, auf meine api hinzufügen –
warum es sagt null 3 –
haben Sie das 'handleSubmit' Methode im Konstruktor binden? Wenn nicht, dann schreibe diese Zeile in den Konstruktor: 'this.handleSubmit = this.handleSubmit.bind (this)' –