[英]Putting a react component (or element?) in an object.
I am making a table on my react website with react-bootstrap-table-next (also known as react-bootstrap-table-2) and am trying to get an icon component to show up in the rows as data instead of what I have now, which is an x, like this: 我正在用react-bootstrap-table-next (也称为react-bootstrap-table-2)在我的react网站上创建一个表,并试图让图标组件作为数据而不是我的内容显示在行中现在,它是一个x,像这样:
A sample of what I currently have for data is: 我目前拥有的数据样本是:
const tools = [{key: 'Android Mobile', qual: "x"}]
But what I want to do is something like: 但是我想做的是这样的:
const tools = [{key: 'Android Mobile', qual: <CheckIcon/>}]
Where CheckIcon is const CheckIcon = () => <Icon icon={check} size={10}/>
(where Icon is being imported from react-icons-kit
). CheckIcon是
const CheckIcon = () => <Icon icon={check} size={10}/>
(其中Icon是从react-icons-kit
导入的)。
Currently the entire page does not render when I do something like that, and I haven't been able to find much information on how to insert a component into an object with React. 目前,当我执行这样的操作时,整个页面无法呈现,而且我还无法找到有关如何使用React将组件插入对象的更多信息。 If there are any tips or tricks anyone has, that would be much appreciated!
如果有人有任何提示或技巧,将不胜感激!
Here is a stackblitz for anyone that wants to play around with the code 这是任何想玩代码的人的快速入门
I think column.formatter
can help you. 我认为
column.formatter
可以为您提供帮助。 there's a online demo: this 有一个在线演示: 此
First, make sure that react-bootstrap-table-next
props data accept React Component. 首先,确保
react-bootstrap-table-next
道具数据接受React组件。
So far what I've found it does not support render a React Component inside the data object. 到目前为止,我发现它不支持在数据对象内部渲染React Component。 https://github.com/react-bootstrap-table/react-bootstrap-table2/blob/master/packages/react-bootstrap-table2/src/bootstrap-table.js#L118
https://github.com/react-bootstrap-table/react-bootstrap-table2/blob/master/packages/react-bootstrap-table2/src/bootstrap-table.js#L118
Feel free if you want to submit a new feature at https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/new 如果您想在https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/new提交新功能, 请随意
I ended up coming to the same conclusion as @Roman Masyhar and ended up taking the cheater's route for now until I end up just making my own table and just using the "✔" character in place of x's and just styling them for the same effect 我最终得出了与@Roman Masyhar相同的结论,并暂时走了作弊者的路线,直到我最终只是制作自己的桌子并只使用“✔”字符代替x并为它们提供相同的样式
In case anyone is curious I did also open a feature request here 万一有人好奇,我也可以在这里打开功能请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.