javascript - 如何在向表中添加列时动态更改列标题
问题描述
这是用于编辑表格单元格的工作代码笔: https ://codepen.io/gges5110/pen/GLPjYr?editors =0010
添加列功能如下:
handleAddColumn = () => {
const { columns } = this.state;
const newColumn = {
title: 'age',
dataIndex: 'age',
};
我该如何做到这一点,以便每次单击“添加列”时,它都会将列标题更改为“1 岁”、“2 岁”、“3 岁”……?
解决方案
试试这个,我使用了你添加的相同计数状态,需要在 addColumn 上更新它。
handleAddColumn = () => {
const { columns } = this.state;
const newColumn = {
title: `age ${this.state.count}`,
dataIndex: 'age',
};
this.setState({
count: this.state.count + 1,
});
this.setState({
columns: [...columns, newColumn]
})
}
推荐阅读
- python - 无法使用 node.js 获取 python 文件输出
- .net - GC.Collect 获取 AppDomain 上有效 MonitoringSurvivedMemorySize 值的最大间隔
- java - 循环二进制字符串问题中的运行时错误
- eclipse - ILOG CPLEX Optimization Studio 无法在 MacOS 上运行
- perl - 如何将二进制数据传递给 Mojolicious Minion?
- javascript - 如何使用 div 在暗/亮模式之间切换?
- python - pip 安装选项不清楚
- r - 使用聚合和变异来获取两列的平均值(更新)
- python - pytest 在断言错误后将测试标记为 PASSED
- reactjs - 在使用 onSnapshot 回调时,如何获得一个调用 firebase.firestore.set 的异步 React 函数来等待?