我使用純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