我使用example来创建/删除链接。https://github.com/facebook/draft-js/blob/master/examples/draft-0-10-0/link/link.html
我知道如何创建和删除链接。
如何更改链接?
我可以检查链接上是否有插入符号:
const contentState = editorState.getCurrentContent();
const startKey = editorState.getSelection().getStartKey();
const startOffset = editorState.getSelection().getStartOffset();
const blockWithLinkAtBeginning = contentState.getBlockForKey(startKey);
const linkKey = blockWithLinkAtBeginning.getEntityAt(startOffset);
if (linkKey) {
linkInstance = contentState.getEntity(linkKey);
if (linkInstance.getData().url) {
...
}
}我需要获取链接文本/html并更改url。我查了replaceData但我不确定..。
发布于 2020-04-24 20:19:51
我知道这是一个古老的帖子,但为了防止别人偶然发现它,你可以使用:
contentState.replaceEntityData(linkKey, { url: newUrl });
https://draftjs.org/docs/api-reference-content-state/#replaceentitydata
https://stackoverflow.com/questions/48179093
复制相似问题