【发布时间】:2013-04-29 17:13:43
【问题描述】:
所以我正在尝试将 CKEditor 的内联编辑与 Knockout.js 集成。我能够成功加载 CKEditor 和 knockout.js。
我似乎无法让 ko.observable 更新属性:
<script type="text/javascript">
var viewModel = function () {
var self = this;
self.editorText = ko.observable('ABC');
self.testNewValue = function () {
console.log(this.editorText());
};
}
ko.applyBindings(new viewModel());
</script>
这里是html:
<div id="editable" contenteditable="true" data-bind="html: editorText">
</div>
<div>
<input type="button" data-bind="click: testNewValue" value="test" />
</div>
console.log 结果始终显示“ABC”,无论您是否更新它。注意:我也试过data-bind="text: editorText"
【问题讨论】:
-
html 绑定是not two-way。您需要创建自己的custom binding for contenteditable。
-
就是这样。谢谢!
-
还有 Froala,它不会把你的 css 内联。淘汰赛插件:github.com/froala/knockout-froala
标签: jquery knockout.js ckeditor