将数据绑定应用于自定义数据绑定中的 dom 元素
我有一个像这样的自定义数据绑定:
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 元素上应用所选绑定。有什么办法吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该调用“ko.applyBindings(viewModel);”创建动态创建的 dom 元素后。
You should call "ko.applyBindings(viewModel);" after your dynamically created dom element is created.