[英]knockout data-bind="html: html , inside html click event is not working
i have html like this : 我有这样的html:
<div class="row thumbnailrow" data-bind="foreach: data">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 thumbpadding" data-bind="html: HtmlText">
</div>
<div>
after getting ajax call : 接到ajax调用后:
success: function (data) { 成功:功能(数据){
$.each(data, function (i, items) {
debugger;
self.data.push(items);
});
}
so it will populate the html binding and google chrome output like this : 因此它将填充html绑定和google chrome输出,如下所示:
<div class="row thumbnailrow" data-bind="foreach: MyProfilesData">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 thumbpadding" data-bind="html: HtmlText"><div>
<div class="pcbtn btnpcedit" data-bind="click: EditProfile" />
</div>
</div>
so here my click: EditProfile
is not working, this event is not fired, when i click on edit button. 所以在这里我
click: EditProfile
不起作用,当我单击编辑按钮时,不会触发此事件。
The html
binding does not process bindings within the inserted HTML. html
绑定不处理插入的HTML中的绑定。 Generally, applying bindings would be unsafe . 通常,应用绑定是不安全的 。 But if this is something you really want to do, you'll need a custom binding like this:
但是,如果这是您真正想做的事情,则需要这样的自定义绑定:
ko.bindingHandlers.htmlBound = {
init: function() {
return { controlsDescendantBindings: true };
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
ko.utils.setHtml(element, valueAccessor());
ko.applyBindingsToDescendants(bindingContext, element);
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.