我有TinyMCE WYSiWYG编辑器呈现文本取决于选定的对象,但遇到绑定的问题。TinyMCE与淘汰赛数据绑定将不会更新
第一个“instanciation”似乎工作,但是从下拉可用文本列表中选择一个新的文本时,编辑器变成空白和Firebug的控制台告诉我:
类型错误:D.hasChildNodes不是一个函数“i”,“string”== typeof r){try {r =“true”=== r?!0:“false”=== r?!1:“null”=== ·R空:+ R ...
和
NS_ERROR_UNEXPECTED:意外的错误 ....../“$ 1”));返回false}});如果(u.getParam( “accessibility_focus”! )){g.add(i.add(k,“a ...
我试图在这里重新创建我的代码:http://jsfiddle.net/xc4sz/1/ 这不是100%,但至少它不起作用。 ;)
如果我不是直接从文本1点击文本2点击“选择选项”,文本会正确显示。
我猜它与下面的“初始化”部分做:
ko.bindingHandlers.tinymce = {
init: function (element, valueAccessor, allBindingsAccessor, context) {
var options = allBindingsAccessor().tinymceOptions || {};
var modelValue = valueAccessor();
var value = ko.utils.unwrapObservable(valueAccessor());
var el = $(element)
//handle edits made in the editor. Updates after an undo point is reached.
options.setup = function (ed) {
console.log(ed)
ed.onChange.add(function (ed, l) {
if (ko.isWriteableObservable(modelValue)) {
modelValue(l.content);
}
});
};
//handle destroying an editor
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
setTimeout(function() { $(element).tinymce().remove() }, 0)
});
//$(element).tinymce(options);
setTimeout(function() { $(element).tinymce(options); }, 0);
el.html(value);
},
update: function (element, valueAccessor, allBindingsAccessor, context) {
var $element = $(element),
value = ko.utils.unwrapObservable(valueAccessor()),
id = $element.attr('id');
//handle programmatic updates to the observable
// also makes sure it doesn't update it if it's the same.
// otherwise, it will reload the instance, causing the cursor to jump.
if (id !== undefined) {
var tinymceInstance = tinyMCE.get(id);
if (!tinymceInstance)
return;
var content = tinymceInstance.getContent({ format: 'raw' });
if (content !== value) {
$element.val(value);
//this should be more proper but ctr+c, ctr+v is broken, above need fixing
//tinymceInstance.setContent(value,{ format: 'raw' })
}
}
}
};
不错的,michaelpapworth。 我可以挑战您将文本的标记/自动标记添加到绑定中吗? ;) –
我不确定在绑定的上下文中“标记/自动标记”的含义。你介意在GitHub上为我的存储库创建一个问题,供我考虑吗? –