简体   繁体   English

将反应组件(或元素?)放入对象中。

[英]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.

相关问题 ReferenceError:未定义元素(Object.<anonymous> ) 在 Intro.js-react、React、Next.js 和 Tailwind CSS</anonymous> - ReferenceError: Element is not defined (Object.<anonymous>) in Intro.js-react, React, Next.js and Tailwind CSS Gatsby:WebpackError [React Intl] 找不到所需的 `intl` 对象。<IntlProvider> 需要存在于组件祖先中 - Gatsby: WebpackError [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry 找不到路线 object。 您的组件是否在导航器的屏幕内? 反应原生 - Couldn't find a route object. Is your component inside a screen in a navigator? React Native 将元素放在Svelte Component中 - Putting an element inside Svelte Component 将 arguments 放入反应组件 function - Putting arguments in react component function 从嵌套对象创建元素。 (反应) - Create Eleements from nested object. (React) 元素类型无效:应为字符串(用于内置组件)或类/函数(用于复合组件),但得到:object。 React-Native - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. React-Native React,将所有功能放在顶级组件中 - React, putting all functions in top level component 找不到导航 object。您的组件是否在 NavigationContainer 中 - Couldn't find a navigation object. Is your component inside NavigationContainer 根据父 object 排序 javascript 中的 object。(反应) - sort an object in javascript, according to parent object.(react)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM