显示模式嵌套在面板中

时间:2015-12-15 13:26:46

标签: javascript twitter-bootstrap bootstrap-modal

我正在使用Bootstrap并做出反应来显示一个面板组件,其中包含一个模态:

<div className="panel panel-default" id="content">
   <div className='panel-heading text-center' id='tableButtons'>
      <h2 className="panel-title central-headingText">Assignments </h2>
   </div>
   <Table/>
</div>

<Table/>的位置:

        <div>
            <div id='tableContainer'>
                <table className="table table-condensed"></table>
            </div>

            {this.state.displayDeleteModal
                ?
                <div id="myModal" className="modal fade" role="dialog">
                    <div className="modal-dialog">

                    <div className="modal-content">
                      <div className="modal-header">
                        <button type="button" className="close" data-dismiss="modal">&times;</button>
                      </div>
                      <div className="modal-body">
                        <p>Are you sure you want to make the deletion?</p>
                      </div>
                    </div>

                  </div>
                </div>
                :
                null
            }

        </div>

但是,当变量this.state.displayDeleteModal变为true时,不显示模态。 我相信这是因为模态嵌套在Bootstrap panel

如何显示模态?

1 个答案:

答案 0 :(得分:1)

您需要根据自己的条件手动打开模态。

使用JavaScript显示模式

$('#myModal').modal('show')

http://getbootstrap.com/javascript/#modals-options

试试这段代码:

    <div>
        <div id='tableContainer'>
            <table className="table table-condensed"></table>
        </div>

        {this.state.displayDeleteModal
            ?
            <div id="myModal" className="modal fade" role="dialog">
                <div className="modal-dialog">

                <div className="modal-content">
                  <div className="modal-header">
                    <button type="button" className="close" data-dismiss="modal">&times;</button>
                  </div>
                  <div className="modal-body">
                    <p>Are you sure you want to make the deletion?</p>
                  </div>
                </div>

              </div>
            </div>
            <script>
                $(function(){
                   $('#myModal').modal('show');
                });
            </script>  
            :
            null
        }

    </div>