如何使动态行距与antd反应

时间:2019-10-24 10:11:36

标签: reactjs antd ant-design-pro

我正在尝试在antd中准备一个具有动态行距的表(数据将是动态的)

我有如下数据。

想要显示如下。你能帮忙吗?

[{"col1":"temp1","col2":"1","col3":"x"}, {"col1":"temp1","col2":"1","col3":"y"}, {"col1":"temp1","col2":"2","col3":"z"}, {"col1":"temp2","col2":"3","col3":"a"}];

enter image description here

1 个答案:

答案 0 :(得分:0)

我们可以编写自定义渲染方法来解决此问题。 样本:

渲染:(值,行,索引)=> {         const obj = {           孩子:价值,           道具: {},         };         如果(索引> = this.state.branch_new_index){           for(让i = 0; index + i!== metrics.length                 &&值===指标[索引+ i]。分支&&                 指标[index] .product ===指标[index + i] .product;我+ = 1){             obj.props.rowSpan = i + 1;             this.state.branch_count = i + 1;           }           this.state.branch_new_index =索引+ this.state.branch_count;           如果(索引+ 1> = metrics.length){             this.state.branch_new_index = 0;           }         }其他{           obj.props.rowSpan = 0;           如果(索引+ 1> = metrics.length){             this.state.branch_new_index = 0;           }         }         返回obj;       }