ページの一部にコンテンツを動的にロードするアプリがあります。コードに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>');
基本的に、ハンドラーを初期化する必要があります。すべてのバインディングを削除して再適用する必要がありますか?