-
-
Save mcarpenterjr/ed5f2eeaacedf6a4186d0b7eeb06c6a3 to your computer and use it in GitHub Desktop.
knockout + jquery chosen binding handler http://jsfiddle.net/tomazy/6A57J/
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
ko.bindingHandlers.chosen = { | |
init: function(element, valueAccessor, allBindings, viewModel, bindingContext){ | |
var $element = $(element); | |
var options = ko.unwrap(valueAccessor()); | |
if (typeof options === 'object') | |
$element.chosen(options); | |
else | |
$element.chosen(); | |
['options', 'selectedOptions', 'value'].forEach(function(propName){ | |
if (allBindings.has(propName)){ | |
var prop = allBindings.get(propName); | |
if (ko.isObservable(prop)){ | |
prop.subscribe(function(){ | |
$element.trigger('chosen:updated'); | |
}); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment