React Js 有條件地應用類屬性 - React Js conditionally applying class attributes

問題:

I want to conditionally show and hide this button group depending on what is passed in from the parent component which looks like this:我想根據從父組件傳入的內容有條件地顯示和隱藏此按鈕組,如下所示:

<TopicNav showBulkActions={this.__hasMultipleSelected} />

.... ....

__hasMultipleSelected: function() {
  return false; //return true or false depending on data
}

.... ....

var TopicNav = React.createClass({
render: function() {
return (
    <div className="row">
        <div className="col-lg-6">
            <div className="btn-group pull-right {this.props.showBulkActions ? 'show' : 'hidden'}">
                <button type="button" className="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                  Bulk Actions <span className="caret"></span>
                </button>
                <ul className="dropdown-menu" role="menu">
                  <li><a href="#">Merge into New Session</a></li>
                  <li><a href="#">Add to Existing Session</a></li>
                  <li className="divider"></li>
                  <li><a href="#">Delete</a></li>
                </ul>
            </div>
        </div>
    </div>
    );
  }
});

Nothing is happening however, with the {this.props.showBulkActions ?然而,{this.props.showBulkActions 沒有發生任何事情? 'show' : 'hidden'}. '顯示':'隱藏'}。 Am I doing anything wrong here?我在這裏做錯了什麼嗎?


解決方案:

參考一: https://stackoom.com/question/2474V
參考二: React Js conditionally applying class attributes
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章