gpt4 book ai didi

reactjs - 数据内的 react 表渲染组件

转载 作者:行者123 更新时间:2023-12-03 09:46:40 25 4
gpt4 key购买 nike

我正在尝试使用 react-table 包( https://www.npmjs.com/package/react-table#example )在数据中添加一个组件

使用包自述文件中的示例,我尝试使用一个花哨的组件将图像添加到单元格:
使用**在代码中跳出...
我也试过:

imageUrl:{<PlaceholderImage width={60} textColor="#fff" text="Image"/>}

例子:
import ReactTable from 'react-table'
import 'react-table/react-table.css'
**import { PlaceholderImage } from 'react-placeholder-image'**

render() {
const data = [{
name: 'Tanner Linsley',
age: 26,
**imageUrl:<PlaceholderImage width={60} textColor="#fff" text="Image"/>,**
friend: {
name: 'Jason Maurer',
age: 23,
}
},{
...
}]

const columns = [{
Header: 'Name',
accessor: 'name' // String-based value accessors!
}, {
Header: 'Age',
accessor: 'age',
Cell: props => <span className='number'>{props.value}</span> // Custom cell components!
}, {
Header: ' ',
accessor: 'imageUrl', // String-based value accessors!
maxWidth: 70,
minWidth:70,
},{
id: 'friendName', // Required because our accessor is not a string
Header: 'Friend Name',
accessor: d => d.friend.name // Custom value accessors!
}, {
Header: props => <span>Friend Age</span>, // Custom header components!
accessor: 'friend.age'
}]

return <ReactTable
data={data}
columns={columns}
/>
}

最佳答案

您将 react 组件传递给需要字符串的数据字段。尝试通过 Cell 自定义您的单元格 Prop :

const columns = [
{
Header: "Image",
accessor: "imageUrl",
maxWidth: 70,
minWidth: 70,
Cell: props => <PlaceholderImage width={60} textColor="#fff" text="Image" />
}
];

关于reactjs - 数据内的 react 表渲染组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57877482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com