0
嗨我想調用我的輸入內的值在表單中我的獲取功能,但它不能讀取請幫助我...我打算做取回後,所以我可以將它插入我的表裏面......我怎樣才能調用我的函數的輸入值ReactJs
我的功能就像是
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);
}
,這是我的形式,其中我想我的
<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>
我嘗試對我的API –
爲什麼它說空 3 –
你綁定在構造函數中'handleSubmit'方法添加?如果沒有,那麼在構造函數中寫下這行:'this.handleSubmit = this.handleSubmit.bind(this)' –