【发布时间】:2017-10-25 15:45:41
【问题描述】:
我正在尝试实现与此问题类似的事情 How do I include a font awesome icon in my svg?
但我有 10 个图标,它们的结构相似,但只有图标不同 我已经返回一个函数来生成 Unicode 字符 作为
static renderIcon (status) {
if (status === 'RED') {
return ''
} else if (status === 'GREEN') {
return ''
} else if (status === YELLOW') {
return ''
}
}
static renderTextWithIcon = (obj) => {
return (
<text x={params.cx} y={params.cy}
className={ css.color}
>
{Utils.renderStatusIconContent(obj.status)}
</text>
)
}
但是如果我尝试不带引号给出它接受并显示图标,它会将字符串呈现为'',但我必须为每种颜色重复相同的代码。如何编写以 Unicode 字符为参数的函数?
【问题讨论】:
标签: javascript reactjs svg unicode