我有这样的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>
收到ajax调用后:
成功:函数(数据){
$.each(data, function (i, items) {
debugger;
self.data.push(items);
});
}
因此它将填充 html 绑定(bind)和 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>
所以这里我的点击:EditProfile
不起作用,当我点击编辑按钮时,这个事件没有被触发。
最佳答案
html
绑定(bind)不会处理插入的 HTML 中的绑定(bind)。一般来说,应用绑定(bind)不安全。但如果这是您真正想做的事情,您将需要像这样的自定义绑定(bind):
ko.bindingHandlers.htmlBound = {
init: function() {
return { controlsDescendantBindings: true };
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
ko.utils.setHtml(element, valueAccessor());
ko.applyBindingsToDescendants(bindingContext, element);
}
};
关于javascript - Knockout data-bind="html : html , 内 html 点击事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28775186/