【问题标题】:Editor.js: how to add unique block id for each editor element as 'id' attribute?Editor.js:如何为每个编辑器元素添加唯一的块 ID 作为 \'id\' 属性?
【发布时间】:2022-11-20 06:46:04
【问题描述】:

我在我的 ReactJS 应用程序中使用 Editor.js。一切都很完美,除了我无法将唯一的块 ID 作为“id”属性传递。

例如,数据是:

{
    "time": 1658299444298,
    "blocks": [
        {
            "id": "sheNwCUP5A",
            "data": {
                "text": "Acceptable Use Policy",
                "level": 2
            },
            "type": "header"
        }
    ],
    "version": "2.25.0"
}

DOM树是

<div class="codex-editor__redactor" style="padding-bottom: 300px;">
  <div class="ce-block">
   <div class="ce-block__content">
    <h2 class="ce-header" contenteditable="false" data-placeholder="">Audit Policy</h2> 
   </div>
  </div>
</div>

要在当前文档中实现锚链接,我需要为从数据传递的每个元素设置“id”属性。

...
<h2 id="sheNwCUP5A" class="ce-header" contenteditable="false" data-placeholder="">Audit Policy</h2>
...

有什么建议吗?

【问题讨论】:

    标签: javascript html reactjs editorjs


    【解决方案1】:

    我也很好奇这个。你有没有想出解决办法?我不认为块工具 API 传递的“数据”与其他地方生成的块 ID 相关:(

    其实Block tools API是把block传入的,你可以通过block.id获取block,缓存起来,然后在我们的render方法中使用这个id。效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 1970-01-01
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-19
      相关资源
      最近更新 更多