Bootstrap手风琴一次打开一个

时间:2017-08-18 11:34:30

标签: html5 css3 twitter-bootstrap-3

我已经创建了一个手风琴并且它在一个循环中,但我只希望一个手风琴一次打开而不是多个。我使用了bootstrap的data parent属性,但它不起作用。任何形式的帮助将受到高度赞赏。 我只希望一次打开一架手风琴。如何实现它。我想因为每个循环我都有这个问题。有什么办法可以解决吗?

这是我的代码:

<?php if(!empty($tickets)) : ?> 

            <?php foreach($tickets as $ticket) : ?>



        <div class="panel-group-custom" id="#panels">



            <div class="panel panel-default mb-0 no-border">

                <div class="panel-heading.panel-heading-custom" >
                <h4 class="panel-title">
                  <div data-toggle="collapse" data-parent="#panels" data-target="#collapse<?php echo $ticket['SupportTicket']['id'] ?>" class="accordion-title">

                      <div class="row">

                          <div class="overflow-hidden">

                              <div class="col-md-2">
                                  <span class="ticket-heading1" title="Ticket ID"><i class="fa fa-ticket" aria-hidden="true"></i> <?php echo $ticket['SupportTicket']['ticket_id']; ?> </span>
                              </div>
                              <div class="col-md-7"><span class="ticket-title"><?php echo $ticket['SupportTicket']['title'] ?></span></div>
                              <div class="col-md-2">
                                  <span class="ticket-heading2" title="Ticket created on"><i class="fa fa-calendar" aria-hidden="true"></i> 
                        <?php $bdate = date_create($ticket['SupportTicket']['modified']); ?>       
                        <?php echo date_format($bdate,"d-M-Y") ?>         


                                  </span>
                              </div>
                              <div class="col-md-1">
                                  <span class="accordion-down">
                                    <i class="fa fa-chevron-down dropdown-toggle down-arrow2" aria-hidden="true"></i>
                                </span>
                              </div>

                          </div>

                      </div>

                  </div>

                </h4>
              </div>


              <div id="collapse<?php echo $ticket['SupportTicket']['id'] ?>" class="panel-collapse collapse">
                    <div class="panel-body">
                        <div class="hidden-overflow ticket">
                             <div class="full-width hidden-overflow ticket-chat">
                                 <p class="color-4 ticket-content"> 
                                    <?php echo $ticket['SupportTicket']['description'] ?>                                 
                                 </p>
                                 <?php if($ticket['SupportTicket']['status']>1) : ?>


                                 <p class="color-1 pull-right ticket-content"> <span class="resolution">Feedback</span>                 
                                    <?php echo $ticket['SupportTicket']['resolution_text']; ?>
                                     <span class="ticket-updated"><span class="bolder"><i class="fa fa-clock-o" aria-hidden="true"></i>
                                            <?php $bdate = date_create($ticket['SupportTicket']['modified']); ?>       
                                            <?php echo date_format($bdate,"d-M-Y") ?>         
                                      </span></span>
                                  </p>
                                  <?php endif ?>
                             </div>
                             <div class="full-width hidden-overflow mt-5">

                            <!-- <p class="ticket-close"><i class="fa fa-window-close" aria-hidden="true"></i> Closed on <span class="bolder">17-Aug-2017 </span></p>-->
                             </div>
                         </div>
                  </div>
              </div>

            </div>

        </div>


            <?php endforeach ?>


        <?php else : ?>
No Records

    <?php endif ?>

1 个答案:

答案 0 :(得分:1)

尝试将#panels div置于foreach循环之外 - 这样他们就在同一组中。

此外,您的#panels div不应在其ID中添加“#”符号。

<?php if(!empty($tickets)) : ?> 
    <div class="panel-group-custom" id="panels"><!-- Remove the '#' from here. -->
        <?php foreach($tickets as $ticket) : ?>
        <div class="panel panel-default mb-0 no-border">
            <div class="panel-heading panel-heading-custom" ><!-- and remove the . from here. -->
            <h4 class="panel-title">
              <div data-toggle="collapse" data-parent="#panels" data-target="#collapse<?php echo $ticket['SupportTicket']['id'] ?>" class="accordion-title">
                  <div class="row">
                      <div class="overflow-hidden">
                          <div class="col-md-2">
                              <span class="ticket-heading1" title="Ticket ID"><i class="fa fa-ticket" aria-hidden="true"></i> <?php echo $ticket['SupportTicket']['ticket_id']; ?> </span>
                          </div>
                          <div class="col-md-7"><span class="ticket-title"><?php echo $ticket['SupportTicket']['title'] ?></span></div>
                          <div class="col-md-2">
                              <span class="ticket-heading2" title="Ticket created on"><i class="fa fa-calendar" aria-hidden="true"></i> 
                                  <?php $bdate = date_create($ticket['SupportTicket']['modified']); ?>       
                                  <?php echo date_format($bdate,"d-M-Y") ?>         
                              </span>
                          </div>
                          <div class="col-md-1">
                              <span class="accordion-down">
                                <i class="fa fa-chevron-down dropdown-toggle down-arrow2" aria-hidden="true"></i>
                            </span>
                          </div>
                      </div>
                  </div>
              </div>
            </h4>
          </div>
          <div id="collapse<?php echo $ticket['SupportTicket']['id'] ?>" class="panel-collapse collapse">
                <div class="panel-body">
                    <div class="hidden-overflow ticket">
                         <div class="full-width hidden-overflow ticket-chat">
                             <p class="color-4 ticket-content"> 
                                <?php echo $ticket['SupportTicket']['description'] ?>                                 
                             </p>
                             <?php if($ticket['SupportTicket']['status']>1) : ?>
                             <p class="color-1 pull-right ticket-content"> <span class="resolution">Feedback</span>                 
                                <?php echo $ticket['SupportTicket']['resolution_text']; ?>
                                 <span class="ticket-updated"><span class="bolder"><i class="fa fa-clock-o" aria-hidden="true"></i>
                                        <?php $bdate = date_create($ticket['SupportTicket']['modified']); ?>       
                                        <?php echo date_format($bdate,"d-M-Y") ?>         
                                  </span></span>
                              </p>
                              <?php endif ?>
                         </div>
                         <div class="full-width hidden-overflow mt-5">
                        <!-- <p class="ticket-close"><i class="fa fa-window-close" aria-hidden="true"></i> Closed on <span class="bolder">17-Aug-2017 </span></p>-->
                         </div>
                     </div>
                 </div>
             </div>
        </div>
        <?php endforeach ?>
    </div><!-- end #panels (moved to after the foreach) -->
<?php else : ?>
    No Records
<?php endif ?>

以下是PHP剥离的工作版本:https://jsfiddle.net/ytcw2sot/