Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxcnunes/5251559 to your computer and use it in GitHub Desktop.
Save maxcnunes/5251559 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
var viewModel = {
students: ko.observableArray([
{ id: 1, name: 'Jake' },
{ id: 2, name: 'Kate' },
{ id: 3, name: 'Mari' }
]),
selected: ko.observable()
};
ko.applyBindings(viewModel);
</script>
<ul data-bind="foreach: students">
<li>
<a href="#" data-bind="click: $root.selected, text: name"></a>
</li>
</ul>
<div data-bind="with: selected">
Id: <span data-bind="text: id"></span>
Name: <span data-bind="text: name"></span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment