Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

ant design 的 DirectoryTree 组件如何修改单击目录不再展开?只需要点击三角符号才打开。

在ant design的官方文档上没找到,可能是我比较菜,希望有了解的朋友可以解答一下,谢谢。

附上官方文档地址 https://ant.design/components...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

demo: https://stackblitz.com/edit/r...
做成受控组件,使用expandedKeys控制展开节点,通过onExpand接收事件,然后更新expandedKeys,类似于


    const [expandedKeys, setExpandedKeys] = useState([])
    
    // ...
    
    <Tree
        expandedKeys={expandedKeys}
        onExpand={(_expandedKeys, {nativeEvent}) => {
            // if event from icon
            setExpandedKeys(_expandedKeys)
            }
        }
    />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...