React-select:如何在选项中显示 HTML [英] React-select: How to display HTML in options
本文介绍了React-select:如何在选项中显示 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道 react-select 是否可以在渲染选项中显示 html.例如,如果获取的 ajax 选项具有 text</b>
,我希望在下拉菜单中看到文本为粗体,而不是看到 text</b>;
.
I am wondering if react-select could show html in rendered options. For example if fetched ajax option has <b>text</b>
, I would like to see text as bold in the dropdown menu instead of seeing <b>text</b>
.
我阅读了文档,但没有找到任何选项.
I read the documentation and I didnt find any option for this.
谢谢
推荐答案
我实施了上述解决方案,但它破坏了可搜索功能.标签需要一个字符串,而不是一个元素.-- 实际上有一个道具/函数可以做到这一点
I implemented the above solution and it broke the searchable feature. The label expects a string, not an element. -- There is actually a prop/function to do this
formatOptionLabel={function(data) {
return (
<span dangerouslySetInnerHTML={{ __html: data.label }} />
);
}}
看看这篇文章:React-Select:如何在将 HTML 传递给选项中的标签值时保持搜索能力
这篇关于React-select:如何在选项中显示 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文