Javascript 草稿JS提及插件-更改提及对象K/V
将我们的富格文本编辑器切换到草稿JS,但我对它有一个问题 提到插件需要一个对象数组,如下所示Javascript 草稿JS提及插件-更改提及对象K/V,javascript,reactjs,rich-text-editor,draftjs,draft-js-plugins,Javascript,Reactjs,Rich Text Editor,Draftjs,Draft Js Plugins,将我们的富格文本编辑器切换到草稿JS,但我对它有一个问题 提到插件需要一个对象数组,如下所示 const mentions = [ { name: 'Matthew Russell', link: 'https://twitter.com/mrussell247', avatar: 'https://pbs.twimg.com/profile_images/517863945/mattsailing_400x400.jpg', } ] 我的问题是,我想搜索名称,
const mentions = [
{
name: 'Matthew Russell',
link: 'https://twitter.com/mrussell247',
avatar: 'https://pbs.twimg.com/profile_images/517863945/mattsailing_400x400.jpg',
}
]
我的问题是,我想搜索名称,但选择后插入值
const mentions = [
{
name: 'Matthew Russell',
link: 'https://twitter.com/mrussell247',
avatar: 'https://pbs.twimg.com/profile_images/517863945/mattsailing_400x400.jpg',
value: "mr5058"
}
]
例如,当用户搜索并选择“Matthew Russel”时,“mr5058”将插入到文本字段中。有人知道解决这个问题的方法吗 您可以通过使用
createsinetingplugin
的sinetingcomponent
属性来实现这一点。示例代码如下:
const mentionPlugin = createMentionPlugin({
mentionTrigger: "@",
mentionComponent: FileMentionComponent
});
其中,我的文件组件是:
export default function FileMentionComponent
({ mention: { name,link,value},
children
}) {
return (
<>
<span>{value}</span>
<span style={{ display: "none" }}>{children}</span>
</>
);
}
导出默认函数文件组件
({提及:{名称、链接、值},
儿童
}) {
返回(
{value}
{儿童}
);
}
请参阅此插件的官方文档:
并搜索“自定义提及组件示例”
干杯