Bootstrap手风琴咏叹调扩展无效

时间:2019-03-19 10:55:38

标签: twitter-bootstrap knockout.js accordion

我正在使用bootstrap 4手风琴。我希望所有卡片都折叠起来作为初始状态。我将aria-expanded设置为false,但是所有卡都显示为扩展。

<div id="accordion">
            <!-- ko foreach: $root.Addons() -->
            <div class="card">
                <div class="card-header" id="headingOne">
                    <h5 class="mb-0">
                        <button class="btn btn-link" data-toggle="collapse" aria-expanded="false" data-bind="text:name, attr: { 'data-target': '#collapsible' +  $index(),'aria-controls': 'collapsible' +  $index() }"></button>
                    </h5>
                </div>
                <div data-bind="attr: { id: 'collapsible' + $index() }" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
                    <div class="card-body">
                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                    </div>
                </div>
            </div>
            <!-- /ko -->
        </div>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您需要更新处于折叠状态的类。

1)在按钮元素中添加collapsed和类btn btn-link

2)从div元素中的show中删除类collapse show

我已经通过上述更改更新了代码。最初应将手风琴保持在折叠状态。

<div id="accordion">
            <!-- ko foreach: $root.Addons() -->
            <div class="card">
                <div class="card-header" id="headingOne">
                    <h5 class="mb-0">
                        <button class="btn btn-link collapsed" data-toggle="collapse" aria-expanded="false" data-bind="text:name, attr: { 'data-target': '#collapsible' +  $index(),'aria-controls': 'collapsible' +  $index() }"></button>
                    </h5>
                </div>
                <div data-bind="attr: { id: 'collapsible' + $index() }" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
                    <div class="card-body">
                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                    </div>
                </div>
            </div>
            <!-- /ko -->
        </div>