Created
September 11, 2012 08:37
-
-
Save iolo/3696932 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select data-bind="options: tickets, optionsCaption: 'Choose...', optionsText: 'name', value: chosenTicket"></select> | |
<button data-bind="enable: chosenTicket, click: resetTicket">Clear</button> | |
<p data-bind="with: chosenTicket"> | |
You have chosen <b data-bind="text: name"></b> | |
($<span data-bind="text: price"></span>) | |
</p> | |
<script type="text/javascript"> | |
function TicketsViewModel() { | |
this.tickets = [ | |
{ name: "Economy", price: 199.95 }, | |
{ name: "Business", price: 449.22 }, | |
{ name: "First Class", price: 1199.99 } | |
]; | |
this.chosenTicket = ko.observable(); | |
this.resetTicket = function() { this.chosenTicket(null) } | |
} | |
ko.applyBindings(new TicketsViewModel(), document.getElementById("liveExample")); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment