我想像这样在 ListItem 中有一个跨度:
<ListItem
primaryText={"<span class='inner'>Some important info</span>" + item.title}
/>
渲染时,我没有得到 HTML span 元素,而是文本 <span class='inner'>Some important info</span>Title of the list item
.如何让 HTML 呈现为 HTML?
最佳答案
删除 span
周围的 ""
,因为当你使用 "
时,它会被转换成 string
,它不会被视为 html
标签。
这样写:
primaryText={<div>
<span className='inner'>Some important info</span>
{item.title}
</div>}
注意: class
是保留关键字,因此要应用 css
类,请使用 className .
关于html - Reactjs:如何将 HTML 放入列表项的 primaryText 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44162450/