Skip to content

Instantly share code, notes, and snippets.

@ashic
Created August 26, 2011 05:09
Show Gist options
  • Save ashic/1172751 to your computer and use it in GitHub Desktop.
Save ashic/1172751 to your computer and use it in GitHub Desktop.
ko
<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