【问题标题】:How to avoid attribute-operation-attribute-exists when calling writer.setAttribute() in CKEditor5?在CKEditor5中调用writer.setAttribute()时如何避免attribute-operation-attribute-exists?
【发布时间】:2022-11-25 05:29:56
【问题描述】:

我正在开发一个简单的 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时出现问题。我总是收到这样的错误:

CKEditor错误:属性操作属性存在{“节点”:{“属性”:{“contentId”:“CORE08954D2EBB7042799E0A059DC90703DD”,“contentName”:“巴黎”,“contentType”:“目的地”,“contentTypeDisplay”:“目的地”,“contentViewing”:“草稿” "categoryLayout":"overview","detailPageId":"","alignment":""},"name":"contentItem"},"key":"width"}

阅读更多:https://ckeditor.com/docs/ckeditor5/latest/framework/guides/support/error-codes.html#error-attribute-operation-attribute-exists

我正在尝试做的事情——将模型属性设置为新值——看起来相当简单。

更新已经有值的模型属性是否有限制?

【问题讨论】:

    标签: ckeditor ckeditor5


    【解决方案1】:

    我最终首先删除了属性然后添加了它:

        editor.model.change( writer => {
            const element = selection.getSelectedElement();
            writer.removeAttribute( 'format', element)
    
            editor.model.change( writer => {
                writer.setAttribute( 'format', 'date', element)
            });
        } );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 2018-07-01
      相关资源
      最近更新 更多