I have a custom data-bind like this :
ko.bindingHandlers.calendar = {
init: function(element, valueAccessor) {
var value = valueAccessor() || {};
var calType = $('<select style=""><option value="gregorian">Miladi</option><option value="islamic">Hicri</option><option value="rumi">Rumi</option></select>');
// Need to something to apply this binding for the calType variable
calType['attr']('data-bind', 'chosen : true');
....
....
$(element).before(calType);
}
};
ko.bindingHandlers.chosen = {
init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
$(element).chosen();
},
update: function(element, valueAccessor, allBindingsAccessor, viewModel) {
$(element).trigger("liszt:updated");
}
};
I want to apply chosen binding on a dynamically created dom element inside the calendar binding. Is there any way to to this ?
You should call “ko.applyBindings(viewModel);” after your dynamically created dom element is created.