Skip to content

Instantly share code, notes, and snippets.

@jonesy827
jonesy827 / knockout-select2.js
Last active May 23, 2018
Knockout Select2 version 3.x binding
View knockout-select2.js
ko.bindingHandlers.select2 = {
init: function (el, valueAccessor, allBindingsAccessor, viewModel) {
ko.utils.domNodeDisposal.addDisposeCallback(el, function () {
$(el).select2('destroy');
});
var allBindings = allBindingsAccessor();
var valueProperty = allBindings.valueProperty || 'value';
var textProperty = allBindings.textProperty || 'text';