【发布时间】:2020-09-21 12:28:12
【问题描述】:
当我尝试捕获新数据时遇到问题,我更改了内容中的某些内容并呈现它。
import React, { Component } from 'react'
import { withNamespaces } from "react-i18next";
class Untitled extends Component {
constructor(props) {
this.columns = [...content]
}
render() {
const columns = this.columns.map((col) => {
return {
...col,
onCell: (record) => ({
record,
dataIndex: col.dataIndex,
title: col.title,
}),
};
});
return (
<div>
{columns}
</div>
)
}
}
export default Untitled
在这里,当我更改 [...content] 中的某些值时,我希望“const 列”将更新这些新值并将其呈现在 return() 中。我确信当 [...content] 更新一个新值时,render() 中有更新。但是“const 列”仍然保留旧值。
P/s:我不能像 this.state { columns: [] } 这样声明 this.columns,因为我不想更改旧开发的代码。正是我想在切换语言时在 this.columns 中获取新值 this.props.t("TEST")。
非常感谢。
【问题讨论】: