我正在开发一个简单的CKEditor5插件。插件的一部分是";命令";执行方式如下:
execute(options) {
const contentItemUtils = this.editor.plugins.get('ContentItemUtils');
const contentItemElement = contentItemUtils.getClosestSelectedContentItemElement(this.editor.model.document.selection);
this.editor.model.change(writer => {
writer.setAttribute('width', options.width, contentItemElement);
});
}
问题发生在我调用writer.setAttribute
时。我总是遇到这样的错误:
CKEditorError:属性操作属性存在{"contentId":"CORE08954D2EB7042799E0A059DC90703DD","contentName":"Paris","contentType":"Destination","Content TypeDisplay":"目的地","内容查看":"草稿","categoryLayout":"概述","详细信息"lPageId":","对齐":"},";name":"contentItem"}"键":"宽度"}
阅读更多:https://ckeditor.com/docs/ckeditor5/latest/framework/guides/support/error-codes.html#error-属性操作属性存在
我试图做的事情——将模型属性设置为一个新值——看起来相当简单。
更新已经具有值的模型属性是否有限制
我首先删除了属性,然后添加了它:
editor.model.change( writer => {
const element = selection.getSelectedElement();
writer.removeAttribute( 'format', element)
editor.model.change( writer => {
writer.setAttribute( 'format', 'date', element)
});
} );