1
我輸入組件接收index
道具看起來是這樣的:提取輸入參數反應成分
renderLibraryInputForm(props) {
return (
<Grid>
<Row>
<Col xs={6} md={3}>
<FormGroup>
<ControlLabel>Library Name</ControlLabel>
<input
type="text"
className="form-control"
name={`libraryName${props.index}`}
onChange={this.onAddLibraryInputChange.bind(this, `libraryName${props.index}`)}
/>
</FormGroup>
</Col>
<Col xs={6} md={2}>
<FormGroup>
<ControlLabel>Available Status</ControlLabel>
<input
type="text"
className="form-control"
name={`availableStatus${props.index}`}
onChange={this.onAddLibraryInputChange.bind(this, `availableStatus${props.index}`)}
/>
</FormGroup>
</Col>
...
</Row>
</Grid>
)
}
onAddLibraryInputChange功能如下:
onAddLibraryInputChange(name, event) {
let inputFields = {}
inputFields[name] = event.target.value
let inputValues = {}
this.setState({inputValues})
}
我一直在試圖插入輸入字段值來獲取對象數組 - inputValues
對象setState
- 具有此形狀:
[{name: "Sunnyvale", status: "Available", distance: 7}, {name: "Palo Alto",
status: " Not Available", distance: 12}, ...]
其中Sunnyvale
和7
分別是數組索引0的輸入字段1和3的值; Palo Alto
和12
分別是數組索引1的輸入字段1和3的值; ...
非常感謝您的建議。