Skip to content

Commit

Permalink
Added example showing that shows how to use the data option
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Sep 16, 2013
1 parent 899b4c0 commit 212f238
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/index.html
Expand Up @@ -75,6 +75,13 @@ <h1>Switching selection mode on-the-fly</h1>
</ul>
</div>

<div class="subset">
<h1>Subset selection (items with even index)</h1>
<ul data-bind="foreach: items, selection: { selection: selection, data: selectable, mode: 'toggle' }" tabindex="-1">
<li data-bind="text: text, css: { selected: selected, focused: focused }"></li>
</ul>
</div>

<script type="text/html" id="items-template">
<li data-bind="text: text, css: { selected: selected, focused: focused }"></li>
</script>
Expand Down Expand Up @@ -181,6 +188,21 @@ <h1>Switching selection mode on-the-fly</h1>

ko.applyBindings(dynamicSelection, window.document.querySelector('.dynamic'));

/**
* Selecting in a subset of the listed items, in this case the items with even indexes
*/
var subsetSelection = {
items: ko.observableArray(createItems(10)),
selection: ko.observableArray()
};
subsetSelection.selectable = ko.computed(function () {
return subsetSelection.items().filter(function (item, index) {
return index % 2 === 0;
});
});

ko.applyBindings(subsetSelection, window.document.querySelector('.subset'));

</script>
</body>
</html>

0 comments on commit 212f238

Please sign in to comment.