我想设置所选的选择字段的值,并附加一个带有空值的新选择字段。我写了两个函数。
this.state.paramCount = 1;
handleChangeParamList(e) {
e.preventDefault();
const str = 'paramSelect' + this.state.paramCount;
const strOld = 'paramSelect' + (this.state.paramCount - 1);
this.setState({
[strOld]: e.target.innerText
});
this.setState({
[str]: e.target.innerText
}, this.handleCreateSelect);
console.log(e.target);
}
handleCreateSelect() {
const str = 'paramSelect' + this.state.paramCount;
const strOld = 'paramSelect' + (this.state.paramCount - 1);
const paramsListing = this.state.paramSelectList;
const paramSelectLists = (<SelectField className="paramNames" onChange={this.handleChangeParamList} value={this.state[str]}>{items}</SelectField>);
paramsListing.push(paramSelectLists);
const count = this.state.paramCount + 1;
this.setState({
paramSelectList: paramsListing,
paramCount: count
});
console.log(str, strOld, this.state[str], this.state[strOld]);
}