简体   繁体   English

Bootstrap Angular.js 手风琴不会自动折叠

[英]Bootstrap Angular.js accordion not auto collapsing

I'm trying to generate an accordion with ng-repeat much as shown in the following sample:我正在尝试使用 ng-repeat 生成手风琴,如以下示例所示:

    <div class="panel-group" id="accordion">
        <div ng-repeat="One_Item in Items_List track by One_Item.Item_ID">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion_{{One_Item.Item_ID}}" href="This_Page/#collapse_{{One_Item.Item_ID}}">
                        {{One_Item.Item_ID}}</a>
                    </h3>
                </div>
                <div class="panel-collapse collapse in" id="collapse_{{One_Item.Item_ID}}">
                    <div class="panel-body">
                        <div class="form-group" style="margin:0px 0px 5px -15px">
                            <label class="control-label col-sm-3">For Item-ID {{One_Item.Item_ID}} the related text is {{One_Item.Text}}</label>
                           <!--- Other stuff... -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

All works OK (in terms of the data being shown), except that when expanding on entry in the accordion, other entry(ies) that were expanded do not collapse.一切正常(就显示的数据而言),除了在手风琴中展开条目时,展开的其他条目不会折叠。

Checked a lot of examples but still cannot figure out why.检查了很多例子,但仍然无法弄清楚原因。

I don't know why do you create new one accordion我不知道你为什么要创造新的手风琴

there is good one at https://angular-ui.github.io/bootstrap/ componentshttps://angular-ui.github.io/bootstrap/components有一个很好的

Default settings uibAccordionConfig默认设置 uibAccordionConfig

closeOthers (Default: true) - Control whether expanding an item will cause the other items to close. closeOthers (默认值:true)- 控制展开一个项目是否会导致其他项目关闭。


Hope it help you希望对你有帮助

This worked for me.这对我有用。 It may need some tweaking to suit your markup exactly.它可能需要一些调整以完全适合您的标记。 The general idea is to problematically collapse the others when one is clicked.一般的想法是在单击一个时有问题地折叠其他的。

var $triggers = $element.find('[data-toggle="collapse"]');
$triggers.on('click', function () {
    var t = $(this);
    $.each($triggers, function(i, $trigger) {
        if ($trigger !== t) {
            $($trigger).parent().find('.collapse').collapse('hide');
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM