【问题标题】:How to modify attributes in annotations in TinyMCE如何在 TinyMCE 中修改注释中的属性
【发布时间】:2021-05-06 07:37:15
【问题描述】:

我正在尝试修改 TinyMCE 中注解的data-author。文档说:

TinyMCE Annotations API 提供了添加、修改和删除注释的能力;侦听文本选择事件并检索具有相同注释名称的所有注释。

我已经注释了我选择的单词,使用

   editor.annotator.annotate('comment', {
    uid: id,
    author: name
  });

输出:
<span class=\"mce-annotation\" data-mce-annotation-uid=\"7\" data-mce-annotation-author=\"name1\" data-mce-annotation=\"comment\">Advice</span>

在该代码中,我已成功注释所选单词,但对于某些事件,我想更改注释单词的作者,这是我的代码:

   editor.annotator.annotate('comment', {
    uid: id,
    author: newName
  });

输出:
<span class=\"mce-annotation\" data-mce-annotation-uid=\"7\" data-mce-annotation-author=\"name1\" data-mce-annotation=\"comment\"><span class=\"mce-annotation\" data-mce-annotation-uid=\"7\" data-mce-annotation-author=\"name2\" data-mce-annotation=\"comment\">Advice</span></span>

我想既然选择的单词已经注释了,通过使用上面的代码我可以改变作者。但它只是在原来的span 中创建了另一个span

我想要的只是编辑或更改某些事件的其他值的 data-mce-annotation-author 值。

有没有人尝试过这个问题或遇到过这个问题?非常感谢!

【问题讨论】:

    标签: javascript annotations tinymce wysiwyg tinymce-plugins


    【解决方案1】:

    我找到了解决方案。

    您只需要使用 Retrieving All Annotations for a Particular Annotation Name

    我更改特定注释器属性的解决方案:

    const comments = editor.annotator.getAll(this.name);
    const comment = comments[id][0];
    comment.setAttribute('data-mce-annotation-author', newName);
    editor.save();
    

    【讨论】:

      猜你喜欢
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-15
      相关资源
      最近更新 更多