反应式表格动态列,无存取符

问题描述 投票:0回答:1

我想对一个对象进行迭代,并根据这个对象制作列,因为这些列的逻辑和外观是一样的。

const customColumns = myObject.map(item =>  {
    return {
    Header: '111',
    headerClassName: "excel-table-header-class",
    className: "excel-table-row-class",
    width: 100
}});

以后我会动态地改变头。

问题是我不能启用所有这些列。

在其他列中,我使用了

           columns={[ ..., customColumns ]}

而这不会去。

我可以做

           columns={[ ..., customColumns[0] ]}

而且它是确定的,我看到我的单列,但我想显示所有的列,而不是一个。

后来我想使用类似

   const customColumns = () => {
        const {myObject} = props;
        if (myObject !== undefined && myObject.length !== 0) {
            myObject.map((item, index) => {
                return (
                    {
                        Header: 'C2',
                        headerClassName: "excel-table-header-class",
                        className: "excel-table-row-class",
                        width: 100,                                        
                                 });
                              });
                            }
                          };

但在这种情况下,我甚至不能显示一个单一的列,如customColumns[0]。为什么会出现这种情况?

javascript reactjs react-native react-table
1个回答
0
投票

我在不同的数组中描述了所有的列,并在columns={}中使用了concat方法,这对我来说是有效的。

© www.soinside.com 2019 - 2024. All rights reserved.