如文档中所述,您应该使用 的onSelect
道具。DropdownButton
var DropdownButton = ReactBootstrap.DropdownButton;
var MenuItem = ReactBootstrap.MenuItem;
var Hello = React.createClass ({
getInitialState() {
return { key: null }
},
onSelect(key) {
this.setState({ key: key });
},
render() {
var selected = this.state.key ? <p>Selected: {this.state.key}</p> : '';
return (<div>
<DropdownButton bsStyle="primary" title="Test" onSelect={this.onSelect}>
<MenuItem eventKey='1' active={this.state.key==='1'}>Action</MenuItem>
<MenuItem eventKey='2' active={this.state.key==='2'}>Another action</MenuItem>
<MenuItem eventKey='3' active={this.state.key==='3'}>Active Item</MenuItem>
<MenuItem divider />
<MenuItem eventKey='4' active={this.state.key==='4'}>Separated link</MenuItem>
</DropdownButton>
{selected}
</div>);
}
});
React.render(<Hello/>, document.getElementById('container'));
这是一个工作小提琴:
https://jsfiddle.net/gadr/azm159g4/2/