我使用纯HTML来使用html的select
标记。现在,我试图用react-bootstrap
替换HTML部分。除了react-bootstrap
标签之外,我有类似的东西,但是每当我使用<ButtonGroup>
的react-bootstrap
而不是select
纯HTML标签时,我都会收到不确定的结果。
这是工作:当使用<ButtonGroup>作为“undefined”时,反应引导程序
<select onChange={this.groupBySelector}>
<option value="invoice">GROUP BY INVOICE</option>
<option value="customer">GROUP BY CUSTOMER</option>
<option value="month">GROUP BY MONTH</option>
</select>
这不是工作:
<ButtonGroup>
<DropdownButton title="GROUP BY" id="bg-nested-dropdown" onSelect={this.groupBySelector}>
<MenuItem value="invoice">GROUP BY INVOICE</MenuItem>
<MenuItem value="customer">GROUP BY CUSTOMER</MenuItem>
<MenuItem value="month">GROUP BY MONTH</MenuItem>
</DropdownButton>
</ButtonGroup>
groupBySelector
功能如下:
groupBySelector(event){
console.log(event);
if ((event.target.value)==="invoice"){
this.setState({invoiceType:'invoice'})
} else if ((event.target.value)==="customer") {
this.setState({invoiceType:'customer'})
} else if ((event.target.value)==="month") {
this.setState({invoiceType:'month'})
} else {
this.setState({invoiceType:'invoice'})
}
}
做'onDropdownSelect =(eventKey)=> {this.setState({invoiceType:eventKey}) }'工作!请更新你的答案 – noobie
@noobie我虽然你需要'groupBySelector'事件。另外,由于性能问题,我不建议在这种情况下使用箭头功能。每次组件呈现时,onSelect事件处理程序都会获得一个新的实例:) – mersocarlin
你在关注[this](https://react-bootstrap.github.io/components.html)链接吗? – noobie