[英]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.