o2project / blog.o2p.jp

O2 Project blog
http://blog.o2p.jp
MIT License
0 stars 0 forks source link

Knockoutならタブ切り替えUIが簡単に出来るお話 #5

Closed kubosho closed 10 years ago

kubosho commented 10 years ago
<ul data-bind="foreach: tabLabels">
  <li data-bind="click: $parent.selectTab.bind($parent, $index), text: $data"></li>
</ul>

<div data-bind="foreach: tabContent">
    <div data-bind="visible: isTabSelected() == 0">
    </div>
</div>
tabLabels     = ko.observableArray(['直近', '購入', '初期']);
isTabSelected = ko.observable(0);

selectTab(index: KnockoutObservable<number>) {
    this.isTabSelected(index());
}