【发布时间】:2020-02-05 16:30:28
【问题描述】:
我对 React.js 相当陌生,我相信我理解了主要概念,并且我正在努力寻找有关如何覆盖我正在声明的类的单个属性的文档。
在我的一个组件中,我基于来自Ant Design 的类定义了一个新类MyColumn。架构(继承而不是组合)已经由其他人制作,我无法更改。
import { Table } from "antd";
const { Column } = Table;
// ...
class MyColumn extends Column<Interfaces.myViewEntry> { } // <---
目前,列标题只是向下流动,我需要省略号(以及带有完整列标签的鼠标悬停)或适当的自动换行。可能后者更容易。
为了达到这个目标,我想为MyColumn 设置属性style: { 'white-space': 'unset' }(并且只是那个属性),因为我读到这将允许我为列标题获得正确的自动换行。
有人可以详细说明在我用<-- 标记的行中的括号中要放入什么吗?
背景
在interfaces.tsx 中,我定义了如下内容
export interface myViewEntry{
LastName: string,
FirstName: string,
Result: number,
}
参考文献
- Overwriting and Extending Prototype
- React.js: setState overwriting, not merging
- How to do word-wrap for data using react-table?
- How can we configure the Header of ant design table component?
- How to update nested state properties in React
- Components and Properties 和 Composition and Inheritance 上的 Reactjs 文档
【问题讨论】:
-
当然。我只需要更多信息,您的代码中存在继承吗?这些组件的外观如何?
-
我刚刚再次检查了代码——我想我必须坚持继承。 :-(
MyColumn之后有一个完整的子类层次结构。所以组合是没有选择的。你还能帮我吗? -
这样的继承是个很糟糕的主意。
-
@Dennis Vash:我知道它并不漂亮,但在技术上可行吗?如果是,怎么做?
-
是的,你可以,请提供一个可重现的例子How to create a Minimal, Reproducible Example(你可以使用这样的codesandbox-antd-template,我会相应地向你展示一个例子。
标签: reactjs class inheritance antd