Created
August 26, 2011 05:09
-
-
Save ashic/1172751 to your computer and use it in GitHub Desktop.
ko
This file contains hidden or 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='value:selected, options:availableOptions, optionsText:'name' /> | |
<div data-bind='template:{"name":resolveTemplate, data:selected}' /> | |
var vm = { | |
'selected' : ko.observable(''), | |
'availableOptions' : ko.ObservableArray([{'name':'foo', 'value':'fooval}, {'name':'bar', 'value':'barval'}]), | |
'resolveTemplate' : function(){ | |
var selectedItem; | |
selectedItem = selected(); | |
if(selectedItem){ | |
return doSomeLogicOnSelectedItemAndReturnString(selectedItem); | |
} | |
} | |
}; | |
//selected will actually hold the observable object of the selected option. So, selected() return {name, value} pair. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment