ant-design/components/tree-select/index.zh-CN.md

83 lines
5.1 KiB
Markdown
Raw Normal View History

2016-03-31 14:17:09 +08:00
---
category: Components
2016-09-21 11:28:38 +08:00
subtitle: 树选择
type: 数据录入
2016-09-21 11:28:38 +08:00
title: TreeSelect
2016-03-31 14:17:09 +08:00
---
2015-12-28 19:16:02 +08:00
2016-01-14 21:42:02 +08:00
树型选择控件。
2015-12-28 19:16:02 +08:00
## 何时使用
2016-01-14 21:42:02 +08:00
类似 Select 的选择控件,可选择的数据结构是一个树形结构时,可以使用 TreeSelect例如公司层级、学科系统、分类目录等等。
2015-12-28 19:16:02 +08:00
## API
### Tree props
2017-10-25 10:25:44 +08:00
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| allowClear | 显示清除按钮 | boolean | false |
2018-06-29 17:22:40 +08:00
| autoClearSearchValue | 当多选模式下值被选择,自动清空搜索框 | boolean | true |
2017-10-25 10:25:44 +08:00
| defaultValue | 指定默认选中的条目 | string/string\[] | - |
| disabled | 是否禁用 | boolean | false |
| dropdownClassName | 下拉菜单的 className 属性 | string | - |
2018-06-29 17:22:40 +08:00
| dropdownMatchSelectWidth | 下拉菜单和选择器同宽。默认将设置 `min-width`。 | boolean | true |
2017-10-25 10:25:44 +08:00
| dropdownStyle | 下拉菜单的样式 | object | - |
2019-05-07 14:57:32 +08:00
| filterTreeNode | 是否根据输入项进行筛选,默认用 treeNodeFilterProp 的值作为要筛选的 TreeNode 的属性值 | boolean\|Function(inputValue: string, treeNode: TreeNode) (函数需要返回 bool 值) | Function |
2017-10-25 10:25:44 +08:00
| getPopupContainer | 菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。[示例](https://codepen.io/afc163/pen/zEjNOy?editors=0010) | Function(triggerNode) | () => document.body |
| labelInValue | 是否把每个选项的 label 包装到 value 中,会把 value 类型从 `string` 变为 `{value: string, label: ReactNode, halfChecked(treeCheckStrictly 时有效): string[] }` 的格式 | boolean | false |
2017-10-25 10:25:44 +08:00
| loadData | 异步加载数据 | function(node) | - |
2018-07-02 12:27:16 +08:00
| maxTagCount | 最多显示多少个 tag | number | - |
| maxTagPlaceholder | 隐藏 tag 时显示的内容 | ReactNode/function(omittedValues) | - |
2019-05-07 14:57:32 +08:00
| multiple | 支持多选(当设置 treeCheckable 时自动变为 true | boolean | false |
| placeholder | 选择框默认文字 | string | - |
| searchPlaceholder | 搜索框默认文字 | string | - |
2018-06-29 17:22:40 +08:00
| searchValue | 搜索框的值,可以通过 `onSearch` 获取用户输入 | string | - |
2018-12-01 15:09:00 +08:00
| treeIcon | 是否展示 TreeNode title 前的图标,没有默认样式,如设置为 true需要自行定义图标相关样式 | boolean | false |
2017-08-25 14:46:54 +08:00
| showCheckedStrategy | 定义选中项回填的方式。`TreeSelect.SHOW_ALL`: 显示所有选中节点(包括父节点). `TreeSelect.SHOW_PARENT`: 只显示父节点(当父节点下所有子节点都选中时). 默认只显示子节点. | enum{TreeSelect.SHOW_ALL, TreeSelect.SHOW_PARENT, TreeSelect.SHOW_CHILD } | TreeSelect.SHOW_CHILD |
meger feature to master (#16421) * use ul in list * update snapshot * update comment * feat: TreeSelect support `showSearch` in multiple mode (#15933) * update rc-tree-select * typo * update desc & snapshot * update desc & snapshot * check default showSearch * feat: table customizing variable (#15971) * feat: added table selected row color variable * fix: @table-selected-row-color default is inherit * feat: Upload support customize previewFile (#15984) * support preview file * use promise * dealy load * use canvas of render * use domHook of test * update demo * add snapshot * update types * update testcase * feat: form customizing variables (#15954) * fix: added styling form input background-color * feat: added '@form-warning-input-bg' variable * feat: added '@form-error-input-bg' variable * use li wrap with comment * feat: Support append theme less file with less-variable (#16118) * add override * add override support * update doc * feat: dropdown support set right icon * docs: update doc of dropdown component * style: format dropdown-button.md * test: update updateSnapshot * style: format dropdown-button.md * test: update updateSnapshot * test: update updateSnapshot * style: change style of dropdown-button demo * fix: fix document table order * feat: Support SkeletonAvatarProps.size accept number (#16078) (#16128) * chore:update style of demo * feat: Notification functions accept top, bottom and getContainer as arguments * drawer: add afterVisibleChange * rm onVisibleChange * update * feat: 🇭🇷 hr_HR locale (#16258) * Added Croatian locale * fixed lint error * :white_check_mark: Add test cases for hr_HR * :memo: update i18n documentation * feat: add `htmlFor` in Form.Item (#16278) * add htmlFor in Form.Item * update doc * feat: Button support `link` type (#16289) close #15892 * feat: Add Timeline.Item.position (#16148) (#16193) * fix: Timeline.pendingDot interface documentation there is a small problem (#16177) * feat: Add Timeline.Item.position (#16148) * doc: add version infomation for Timeline.Item.position * refactor: Update Tree & TreeSelect deps (#16330) * use CSSMotion * update snapshot * feat: Collapse support `expandIconPosition` (#16365) * update doc * support expandIconPosition * update snapshot * feat: Breadcrumb support DropDown (#16315) * breadcrumbs support drop down menu * update doc * add require less * fix test * fix md doc * less code * fix style warning * update snap * add children render test * feat: TreeNode support checkable * feat: add optional to support top and left slick dots (#16186) (#16225) * add optional to support top and left slick dots * update carousel snapshot * Update doc, add placement demo * update carousel placement demo snapshots * rename dots placement to position * update vertical as deprecated * rename dotsPosition to dotPosition * refine code * add warning testcase for vertical * remove unused warning * update expression * Additional test case for dotPosition * refactor: Upgrade `rc-tree-select` to support pure React motion (#16402) * upgrade `rc-tree-select` * update snapshot * 3.17.0 changelog * fix warning * fix review warning
2019-05-06 12:04:39 +08:00
| showSearch | 是否支持搜索框 | boolean | 单选:`false` \| 多选:`true` |
2017-10-25 10:25:44 +08:00
| size | 选择框大小,可选 `large` `small` | string | 'default' |
2018-09-16 19:47:00 +08:00
| suffixIcon | 自定义的选择框后缀图标 | ReactNode | - |
| treeCheckable | 显示 checkbox | boolean | false |
2017-08-25 17:20:11 +08:00
| treeCheckStrictly | checkable 状态下节点选择完全受控(父子节点选中状态不再关联),会使得 `labelInValue` 强制为 true | boolean | false |
| treeData | treeNodes 数据,如果设置则不需要手动构造 TreeNode 节点value 在整个树范围内唯一) | array\<{value, title, children, \[disabled, disableCheckbox, selectable]}> | \[] |
2019-03-07 20:40:06 +08:00
| treeDataSimpleMode | 使用简单格式的 treeData具体设置参考可设置的类型 (此时 treeData 应变为这样的数据结构: \[{id:1, pId:0, value:'1', title:"test1",...},...], `pId` 是父节点的 id) | false\|object\<{ id: string, pId: string, rootPId: string }> | false |
2017-10-25 10:25:44 +08:00
| treeDefaultExpandAll | 默认展开所有树节点 | boolean | false |
| treeDefaultExpandedKeys | 默认展开的树节点 | string\[] | - |
| treeExpandedKeys | 设置展开的树节点 | string\[] | - |
| treeNodeFilterProp | 输入项过滤对应的 treeNode 属性 | string | 'value' |
| treeNodeLabelProp | 作为显示的 prop 设置 | string | 'title' |
2017-10-25 10:25:44 +08:00
| value | 指定当前选中的条目 | string/string\[] | - |
| onChange | 选中树节点时调用此函数 | function(value, label, extra) | - |
| onSearch | 文本框值变化时回调 | function(value: string) | - |
| onSelect | 被选中时调用 | function(value, node, extra) | - |
| onTreeExpand | 展示节点时调用 | function(expandedKeys) | - |
2015-12-28 19:16:02 +08:00
### Tree 方法
2019-05-07 14:57:32 +08:00
| 名称 | 描述 |
| ------- | -------- |
| blur() | 移除焦点 |
2017-12-29 20:22:58 +08:00
| focus() | 获取焦点 |
2015-12-28 19:16:02 +08:00
### TreeNode props
2016-08-05 11:47:31 +08:00
2016-02-01 14:36:41 +08:00
> 建议使用 treeData 来代替 TreeNode免去手工构造麻烦
2015-12-28 19:16:02 +08:00
2017-10-25 10:25:44 +08:00
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
2018-09-09 21:18:34 +08:00
| selectable | 是否可选 | boolean | true |
| disableCheckbox | 禁掉 checkbox | boolean | false |
2017-10-25 10:25:44 +08:00
| disabled | 是否禁用 | boolean | false |
| isLeaf | 是否是叶子节点 | boolean | false |
2017-10-25 10:25:44 +08:00
| key | 此项必须设置(其值在整个树范围内唯一) | string | - |
| title | 树节点显示的内容 | string\|ReactNode | '---' |
| value | 默认根据此属性值进行筛选(其值在整个树范围内唯一) | string | - |
## FAQ
2019-04-03 18:59:41 +08:00
### onChange 时如何获得父节点信息?
从性能角度考虑,我们默认不透出父节点信息。你可以这样获得:<https://codesandbox.io/s/wk080nn81k>