Hide respective div on respective button click

55 views
Skip to first unread message

Trushanti Pare

unread,
Dec 15, 2017, 2:16:01 AM12/15/17
to KnockoutJS
I have 2 divs. One contain toggle buttons and other different divs with charts.
I want to show respective div on respective button click but not able to it. Can please anyone help
 <div class="btn-group" data-bind='foreach: Buttons, visible : Buttons().length >= 1'>
          <button type="button" data-bind="attr: { class: active()==true?'btn focus':'btn'}, click: $root.buttonclick" data-toggle="buttons"><span data-bind="text: title"></span></button>
 </div>

<div class="tab-content" data-bind='foreach: Buttons'>
        <div data-bind="attr: { class: active()==true?'tab-pane row active':'tab-pane row',id:id }" data-toggle="buttons">
                <div data-bind="foreach: DataSources, attr: { class: active()==true?'tab-pane row active':'tab-pane row',id:id }">
                         ...
                </div>
       </div>
</div>

by this code button's class getting changed but div's not.

Andrew Vickers

unread,
Dec 20, 2017, 12:45:23 PM12/20/17
to KnockoutJS
The best way that I've found to implement tabs in KO is with Michael Best's knockout-switch-case.

You would simply create an observable such as this.chart.  Your button clicks would update the observable to something like 'bar' or 'pie'.

Then you would switch the observable with cases containing each of the tabs contents.

You can also accomplish this with the if binding, but it's a lot more verbose.
Reply all
Reply to author
Forward
0 new messages