我定义了editorStyleMap并使用它们
const editorStyleMap = { Choose: { color: '#4880f0' }, Black: { color: '#000000' } }然后我得到了inlineStyleRanges数组
const messageBlocks=convertToRaw(editorState.getCurrentContent()).blocks[0].inlineStyleRanges;我安慰数组中的每一项,结果如下,项目的样式可以是“选择”或“黑色”
{偏移距: 3,长度: 3,样式:‘选择’}{偏移: 6,长度: 5,样式:‘黑色’}{偏移: 11,长度: 3,样式:‘选择’}{偏移: 14,长度: 1,样式:‘黑色’}}
但是当我想用if来判断风格的类型
if(item.style==='Choose')终端报告错误
‘此条件将始终返回'false’,因为'DraftInlineStyleType‘和’选择‘类型没有重叠。
似乎styleType只能是默认类型,比如‘粗体’和‘斜体’。
我不知道为什么??如果你能帮助我,我将不胜感激:)
发布于 2022-10-21 06:14:42
我用一种奇怪的方法来解决这个问题。只需使用 string ()方法将item.style转换为string类型,该字符串可以是您定义的任何内容
if(String(item.style)==='Choose')终端不报告错误。
https://stackoverflow.com/questions/74026809
复制相似问题