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}
/>