我有这样的自定义数据绑定:
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");
}
};
我想在日历绑定中的动态创建的dom元素上应用选择的绑定。有没有办法解决这个问题?
答案 0 :(得分:2)
你应该调用“ko.applyBindings(viewModel);”在创建动态创建的dom元素之后。