Skip to content

Instantly share code, notes, and snippets.

@iolo
Created September 11, 2012 08:37
Show Gist options
  • Save iolo/3696932 to your computer and use it in GitHub Desktop.
Save iolo/3696932 to your computer and use it in GitHub Desktop.
<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