我从react-bootstrap documentation实现了一个多选下拉菜单。
它不允许我进行多项选择,而只能获得最后单击的选项。我将状态变量设置为数组。我还想念什么?应用是使用create-react-app创建的。
我在类构造函数中将状态设置为数组。事件处理程序的绑定也可以在构造函数中完成。
接下来,我将显示事件处理程序,然后显示带有onChange
并将其值设置为state的表单组。 (请注意,我有一个下拉菜单可以正常工作。)
然后我将此值传递给几个类,然后将其解析为JSON。最后的粘贴是这些类。我删除了其他参数,以便于阅读,任何想法,随时询问更多信息。
this.state = {
codeCoverage: [],}
this.handleCodeCoverageChange = this.handleCodeCoverageChange.bind(this);
//Event handlers below
handleCodeCoverageChange(event){
this.setState({
codeCoverage: event.target.value
})
}
<Form.Group>
<Form.Label>Please choose your desired code coverage software(s)</Form.Label>
<Form.Control as="select" value={this.state.codeCoverage} onChange={this.handleCodeCoverageChange} multiple>
<option value="">--Please choose an option--</option>
<option value="cobertura">Cobertura</option>
<option value="sonarcube">Sonarcube</option>
</Form.Control>
</Form.Group>
var configurator = new Configurator(this.state.codeCoverage)
class Configurator
{
constructor(
code_coverage)
{
this.pipeline = new Pipeline(code_coverage)
}
}
class Pipeline
{
constructor(code_coverage)
{
this.analysisAndSecurity = new AnalysisAndSecurity(code_coverage)
}
class AnalysisAndSecurity{
parameter
constructor(code_coverage)
{
this.code_coverage = code_coverage
}
}