Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 草稿JS提及插件-更改提及对象K/V_Javascript_Reactjs_Rich Text Editor_Draftjs_Draft Js Plugins - Fatal编程技术网

Javascript 草稿JS提及插件-更改提及对象K/V

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', } ] 我的问题是,我想搜索名称,

将我们的富格文本编辑器切换到草稿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',
    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}
{儿童}
);
}
请参阅此插件的官方文档: 并搜索“自定义提及组件示例”

干杯