我在用
https://github.com/olahol/react-tagsinput
用于在我的应用程序中创建标记的库当我试图将renderTag属性绑定到自定义函数时,会发生非常奇怪的事情我想我遗漏了一点与JavaScript相关的内容,而不是react。
即使typeof标记类型在组件上返回'string',当我试图呈现它时,它会呈现[object object]| hello为什么要渲染对象?
defaultRenderTag = (customProps, props) => {
let { tag, key, disabled, onRemove, classNameRemove, getTagDisplayValue, ...other } = props
let { tagType } = customProps;
// This returns 'string'
console.log(typeof tagType)
return (
<span key={key} {...other}>
{/* The type of the tag: */}
{
tagType ? (
// This returns "[object Object] | work"
<span className="react-tagsinput-tagtype"> {tagType} </span> + ' | '
) : null
}
{getTagDisplayValue(tag)}
{!disabled &&
<a className={classNameRemove} onClick={(e) => onRemove(key)} />
}
</span>
)
}
这是我使用上述功能的主要组件:
<TagsInput
...
renderTag={this.defaultRenderTag.bind(this, { tagType: 'personal' })}
...
/>