2020-01-15 12:13:20 +08:00
|
|
|
---
|
|
|
|
order: 9
|
|
|
|
title:
|
|
|
|
zh-CN: 虚拟滚动
|
|
|
|
en-US: Virtual scroll
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
使用 `height` 属性则切换为虚拟滚动。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Use virtual list through `height` prop.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2020-01-15 12:13:20 +08:00
|
|
|
import { Tree } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import type { DataNode } from 'antd/lib/tree';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React from 'react';
|
2020-01-15 12:13:20 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const dig = (path = '0', level = 3) => {
|
2020-01-15 12:13:20 +08:00
|
|
|
const list = [];
|
|
|
|
for (let i = 0; i < 10; i += 1) {
|
|
|
|
const key = `${path}-${i}`;
|
2022-05-19 09:46:26 +08:00
|
|
|
const treeNode: DataNode = {
|
2020-01-15 12:13:20 +08:00
|
|
|
title: key,
|
|
|
|
key,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (level > 0) {
|
|
|
|
treeNode.children = dig(key, level - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
list.push(treeNode);
|
|
|
|
}
|
|
|
|
return list;
|
2022-05-19 09:46:26 +08:00
|
|
|
};
|
2020-01-15 12:13:20 +08:00
|
|
|
|
|
|
|
const treeData = dig();
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => <Tree treeData={treeData} height={233} defaultExpandAll />;
|
|
|
|
|
|
|
|
export default App;
|
2020-01-15 12:13:20 +08:00
|
|
|
```
|