2016-06-23 8 views
1
<DropdownButton bsStyle="default" title="No caret" noCaret id="dropdown-no-caret"> 
    <MenuItem eventKey="1">Action</MenuItem> 
    <MenuItem eventKey="2">Another action</MenuItem> 
    <MenuItem eventKey="3">Something else here</MenuItem> 
    <MenuItem eventKey="4">Separated link</MenuItem> 
</DropdownButton> 

私は、メニュー項目のいずれかが選択されたときにどのようにボタンのタイトルを更新してしまう、反応-ブートストラップコンポーネントの例からhttps://react-bootstrap.github.io/components.html#btn-dropdowns-nocaretボタンのタイトルを更新するには?

をこの例を取りましたか?

答えて

2

セット状態を使用して、タイトルとは状態に

<DropdownButton bsStyle="default" title={this.state.btnTitle} noCaret id="dropdown-no-caret" onChange={this.handleChange}> 
    <MenuItem eventKey="1">Action</MenuItem> 
    <MenuItem eventKey="2">Another action</MenuItem> 
    <MenuItem eventKey="3">Something else here</MenuItem> 
    <MenuItem eventKey="4">Separated link</MenuItem> 
</DropdownButton> 

機能を更新することができDropdownButtononChangeイベントを追加:あなたはどんなMenuItemを選択した場合

handleChange =() => { 
    var val = 'someValue'; 
    this.setState({btnTitle: val}); 
} 

これは、タイトルを変更します。このソリューションがお役に立てば幸いです。

+0

ありがとうございます。私は別のDropdownButtonが更新されると更新されるbtnTitle状態を設定するのが怖かったです。私はいくつかの結果を得ることができましたが、あなたの答えは完全に説明されています。 – lasimonne

+0

お手伝いします! :) –

関連する問題