Devi scrivere il tuo gestore di binding personalizzato affinché la tua proprietà osservabile sia collegata con un'istanza di CKEditor.
Innanzitutto, è possibile iniziare dall'associazione personalizzata trovata here. Uno dei post contiene un'associazione personalizzata, anche se non sono sicuro che funzioni. Devi controllare. Ho copiato qui, i crediti non vanno a me ovviamente:
ko.bindingHandlers.ckEditor = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var txtBoxID = $(element).attr("id");
var options = allBindingsAccessor().richTextOptions || {};
options.toolbar_Full = [
['Source', '-', 'Format', 'Font', 'FontSize', 'TextColor', 'BGColor', '-', 'Bold', 'Italic', 'Underline', 'SpellChecker'],
['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl'],
['Link', 'Unlink', 'Image', 'Table']
];
// handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
if (CKEDITOR.instances[txtBoxID]){
CKEDITOR.remove(CKEDITOR.instances[txtBoxID]);
}
});
$(element).ckeditor(options);
// wire up the blur event to ensure our observable is properly updated
CKEDITOR.instances[txtBoxID].focusManager.blur = function() {
var observable = valueAccessor();
observable($(element).val());
};
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var val = ko.utils.unwrapObservable(valueAccessor());
$(element).val(val);
}
}
Un utilizzo tipico allora sarebbe nel codice HTML:
<textarea id="txt_viewModelVariableName"
data-bind="ckEditor: viewModelVariableName"></textarea>
In secondo luogo, si potrebbe verificare la custom binding handler for TinyMCE inizialmente scritto da Ryan Niemeyer e aggiornato da altre persone di talento. Forse TinyMCE potrebbe funzionare per te al posto di CKEditor?
Il bind html è [non bidirezionale] (https://github.com/SteveSanderson/knockout/issues/430). Devi creare il tuo [binding personalizzato per contenteditable] (http://stackoverflow.com/questions/7904522/knockout-content-editable-custom-binding). – nemesv
Ecco fatto. Grazie! – jmogera
C'è anche Froala, che non metterà il tuo css in linea. Plugin knockout: https: // github.com/froala/knockout-froala –