Knockout Options Text Binding

http://stackoverflow.com/questions/13903007/knockout-options-text-binding

by photo_tom

HTML

<link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/themes/humanity/jquery-ui.css">
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.2.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.js"></script>
<select data-bind="options: assemblies, optionsText: 'Name', value: selectedAssembly">
</select>
<br />
Name <input type="text" data-bind="value: selectedAssembly" />
<br />
SelectedAssembly = <span data-bind="text: selectedAssembly"></span>

JavaScript

var vm = {};
var vm.assemblies = ko.mapping.fromJS([{
    "Id": 1,
    "Name": "Foo"},
{
    "Id": 2,
    "Name": "Bar"}]);

vm.selectedAssembly = ko.observable();
ko.applyBindings(vm);