antd tree 有個scrollTo方法,是在ref.current里面,使用方法如下
注意滾動到子級節點時,父節點要處在展開狀態下,先展開再滾動,動態賦值的時候也要先展開再賦值再滾動
import { Tree, Button,} from 'antd';
import React, { useState, useRef } from 'react';
const treeRef = useRef();
<Button
onClick={() => {
treeRef.current.scrollTo({ key: "0-0-0-5-4" });
}}
>Scroll To</Button>
<Tree
ref={treeRef}
blockNode
checkable
onCheck={onCheck}
height={700}
checkedKeys={checKeys}
treeData={treeData}
onExpand={expendData}
/>
