简体   繁体   English

Object.keys() 返回在 Ant Design 表列渲染中不起作用

[英]Object.keys() return not working in Ant Design table column rendering

I'm trying to render an Ant Design table featuring a people column which should look like this:我正在尝试渲染一个Ant Design 表,其中包含一个 people 列,它应该如下所示:

Adults: 2 Children: 3成人: 2儿童: 3

Here's a sample dataSource object:这是一个示例dataSource对象:

{
    id: 'KRO066',
    key: 'KRO066',
    date: '01/01/2020',
    people: { adults: 2, children: 3 },
    status: 'Confirmed',
    total: '563.25',
}

Here's the people column render function in my column object:这是我的column对象中的 people 列渲染函数:

{
    title: 'People',
    dataIndex: 'people',
    key: 'people',
    render: people => Object.keys(people).forEach(function (type, i) {
        return <span key={i}><strong>{type}:</strong>{people[type]}</span>;
    })

}

The column does not return anything, instead, I get an empty cell.该列不返回任何内容,而是得到一个空单元格。

What's wrong with the render function?渲染函数有什么问题?

Use Object.keys(people).map instead of Object.keys(people).forEach使用Object.keys(people).map而不是Object.keys(people).forEach

Credit @Hamms in the question comments在问题评论中感谢@Hamms

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM