[英]`ref` issue with react-bootstrap elements
我正在嘗試通過ref ='roleType'的DropdownButton選擇獲取的get值,但是我嘗試的任何操作均失敗。
<DropdownButton ref='roleType' bsStyle='link' title='Role' key='1' bsSize='xsmall'>
{_items}
</DropdownButton>
我嘗試了以下方法:
React.findDOMNode(this.refs.roleType)
this.refs.roleType.getDOMNode()
注意:我不確定這是否重要。 DropdownButton
在Panel
內部,該Panel
在div
的section
內部。
如文檔所述,您應該使用DropdownButton
的onSelect
道具。
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'));
這是一個工作的小提琴:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.