我有一个应用程序,我在其中将内容动态加载到页面的某些部分。有时代码具有data-bind
属性,这些属性似乎被 KnockOutJS 忽略了。
HTML:
<div data-bind="html: code">
this text is replaced by the JavaScript
</div>
function AppView() {
var self = this;
// This sets the code
self.code = ko.observable('<div>this shouldnt show</div>');
self.stuff = ko.observable('this should show');
}
var app = new AppView();
ko.applyBindings(app);
// Later we override the code. We're setting an observable, so the app should notice.
app.code('<div data-bind="text: stuff">this shouldnt show either</div>');
本质上,我需要初始化处理程序。我是否需要删除所有绑定并重新申请?