npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@beisen-phoenix/common-tree

v1.0.1

Published

--- category: Components type: 数据展示 title: Tree subtitle: 树形控件 ---

Readme


category: Components type: 数据展示 title: Tree subtitle: 树形控件

何时使用

文件夹、组织架构、生物分类、国家地区等等,世间万物的大多数结构都是树形结构。使用树控件可以完整展现其中的层级关系,并具有展开收起选择等交互功能。

API

Tree props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | autoExpandParent | 是否自动展开父节点 | boolean | true | | checkable | 节点前添加 Checkbox 复选框 | boolean | false | | checkedKeys | (受控)选中复选框的树节点(注意:父子节点有关联,如果传入父节点key,则子节点自动选中;相应当子节点key都传入,父节点也自动选中。当设置checkablecheckStrictly,它是一个有checkedhalfChecked属性的对象,并且父子节点的选中与否不再关联 | string[] | {checked: string[], halfChecked: string[]} | [] | | checkStrictly | checkable状态下节点选择完全受控(父子节点选中状态不再关联) | boolean | false | | defaultCheckedKeys | 默认选中复选框的树节点 | string[] | [] | | defaultExpandAll | 默认展开所有树节点 | boolean | false | | defaultExpandedKeys | 默认展开指定的树节点 | string[] | [] | | defaultExpandParent | 默认展开父节点 | bool | true | | defaultSelectedKeys | 默认选中的树节点 | string[] | [] | | disabled | 将树禁用 | bool | false | | draggable | 设置节点可拖拽(IE>8) | boolean | false | | expandedKeys | (受控)展开指定的树节点 | string[] | [] | | filterTreeNode | 按需筛选树节点(高亮),返回true | function(node) | - | | loadData | 异步加载数据 | function(node) | - | | loadedKeys | (受控)已经加载的节点,需要配合 loadData 使用 | string[] | [] | | multiple | 支持点选多个节点(节点本身) | boolean | false | | selectedKeys | (受控)设置选中的树节点 | string[] | - | | showIcon | 是否展示 TreeNode title 前的图标,没有默认样式,如设置为 true,需要自行定义图标相关样式 | boolean | false | | switcherIcon | 自定义树节点的展开/折叠图标 | React.ReactElement | - | | showLine | 是否展示连接线 | boolean | false | | onCheck | 点击复选框触发 | function(checkedKeys, e:{checked: bool, checkedNodes, node, event}) | - | | onDragEnd | dragend 触发时调用 | function({event, node}) | - | | onDragEnter | dragenter 触发时调用 | function({event, node, expandedKeys}) | - | | onDragLeave | dragleave 触发时调用 | function({event, node}) | - | | onDragOver | dragover 触发时调用 | function({event, node}) | - | | onDragStart | 开始拖拽时调用 | function({event, node}) | - | | onDrop | drop 触发时调用 | function({event, node, dragNode, dragNodesKeys}) | - | | onExpand | 展开/收起节点时触发 | function(expandedKeys, {expanded: bool, node}) | - | | onLoad | 节点加载完毕时触发 | function(loadedKeys, {event, node}) | - | | onRightClick | 响应右键点击 | function({event, node}) | - | | onSelect | 点击树节点触发 | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) | - |

TreeNode props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | disableCheckbox | 禁掉 checkbox | boolean | false | | disabled | 禁掉响应 | boolean | false | | icon | 自定义图标。可接收组件,props 为当前节点 props | ReactNode/Function(props):ReactNode | - | | isLeaf | 设置为叶子节点(设置了loadData时有效) | boolean | false | | key | 被树的 (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys 属性所用。注意:整个树范围内的所有节点的 key 值不能重复! | string | 内部计算出的节点位置 | | selectable | 设置节点是否可被选中 | boolean | true | | title | 标题 | string|ReactNode | '---' |

DirectoryTree props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | expandAction | 目录展开逻辑,可选 false 'click' 'doubleClick' | string | click |

注意

3.4.0 之前: 树节点可以有很多,但在设置checkable时,将会花费更多的计算时间,因此我们缓存了一些计算结果(this.treeNodesStates)来复用,避免多次重复计算,以此提高性能。但这也带来了一些限制,当你异步加载树节点时,你需要这样渲染树:

{this.state.treeData.length
  ? <Tree>{this.state.treeData.map(data => <TreeNode />)}</Tree>
  : 'loading tree'}

FAQ

在 showLine 时,如何隐藏子节点图标?

文件图标通过 switcherIcon 来实现,如果不需要你可以覆盖对应的样式:https://codesandbox.io/s/883vo47xp8