Angular CDK tree API 参考文档
import {CdkTreeModule} from '@angular/cdk/tree';
指令
CdkNestedTreeNode
extends
CdkTreeNode
嵌套节点是 <cdk-tree>
的子节点。它适用于嵌套树。通过在树节点模板中使用 cdk-nested-tree-node
组件,会把父节点的子节点添加到树节点模板的 cdkTreeNodeOutlet
中。 该节点的子节点会自动添加到 cdkTreeNodeOutlet
中。
Nested node is a child of <cdk-tree>
. It works with nested tree.
By using cdk-nested-tree-node
component in tree node template, children of the parent node will
be added in the cdkTreeNodeOutlet
in tree node template.
The children of node will be automatically added to cdkTreeNodeOutlet
.
属性
名称 | 描述 |
---|---|
|
树节点的数据。 The tree node's data. |
|
|
|
|
|
子节点的占位符。 The children node placeholder. |
@Input()
已弃用
|
树节点的角色是什么。 The role of the tree node. |
方法
focus | |
---|---|
让此菜单项获得焦点。是对 FocusableOption 的实现。 Focuses the menu item. Implements for FocusableOption. |
updateChildrenNodes | |
---|---|
把子节点的数据节点添加到 NodeOutlet 中 Add children dataNodes to the NodeOutlet |
|
参数 Parameters |
|
children? T[]
|
|
CdkTreeNodeDef
CdkTree 的数据节点定义。保存该节点的模板和一个 when 谓词,用于描述该节点要在何时使用。
Data node definition for the CdkTree. Captures the node's template and a when predicate that describes when this node should be used.
属性
名称 | 描述 |
---|---|
@Input( cdkTreeNodeDefWhen)
|
如果该节点模板应该应用在所提供的节点数据和索引上,则该函数返回 true。如果未定义,那么当该函数对该数据返回 true 时,该节点将被认为是默认的节点模板。对于每一个节点,至少要传入一个 when 函数或者用 undefined 表示默认行为。 Function that should return true if this node template should be used for the provided node data and index. If left undefined, this node will be considered the default node template to use when no other when functions return true for the data. For every node, there must be at least one when function that passes or an undefined to default. |
|
CdkTreeNodePadding
子树数据节点的缩进量。该指令会在节点中添加 left-padding 以展示层次结构。
Indent for the children tree dataNodes. This directive will add left-padding to the node to show hierarchy.
属性
名称 | 描述 |
---|---|
@Input('cdkTreeNodePaddingIndent')
|
每个级别的缩进。可以是数字或 CSS 字符串。默认值为 40px,来自 Material Design 菜单中的子菜单规范。 The indent for each level. Can be a number or a CSS string. Default number 40px from material design menu sub-menu spec. |
@Input('cdkTreeNodePadding')
|
树节点的深度级别。其衬距将是 The level of depth of the tree node. The padding will be |
|
用于表示缩进值的 CSS 单位。 CSS units used for the indentation value. |
CdkTreeNodeOutlet
嵌套的 CdkNode 出口地标。把 [cdkTreeNodeOutlet]
放到标签上,把子数据节点放到这个出口地标中。
Outlet for nested CdkNode. Put [cdkTreeNodeOutlet]
on a tag to place children dataNodes
inside the outlet.
属性
名称 | 描述 |
---|---|
|
CdkTree
CDK 树组件,用于连接数据源,检索 T
类型的数据,并使用分层结构渲染数据节点。当数据源提供新数据时,会更新数据节点。
CDK tree component that connects with a data source to retrieve data of type T
and renders
dataNodes with hierarchy. Updates the dataNodes when new data is provided by the data source.
属性
名称 | 描述 |
---|---|
@Input()
|
提供一个包含要渲染的最新数据数组的流。受树的视图流窗口影响(即当前屏幕上有哪些数据节点)。数据源可以是数据数组的可观察对象,也可以是要渲染的数据数组。 Provides a stream containing the latest data array to render. Influenced by the tree's stream of view window (what dataNodes are currently on screen). Data source can be an observable of data array, or a data array to render. |
@Input()
|
跟踪函数,用于检查数据变化的差异。类似于 Tracking function that will be used to check the differences in data changes. Used similarly
to |
@Input()
|
树控制器 The tree controller |
|
这个流包含哪些节点正显示在屏幕上的最新信息。可以被数据源用作该提供哪些数据的线索。 Stream containing the latest information on what rows are being displayed on screen. Can be used by the data source to as a heuristic of what data should be provided. |
方法
insertNode | |
---|---|
为数据节点模板创建嵌入式视图,并把它放在数据节点视图容器的正确索引位置。 Create the embedded view for the data node template and place it in the correct index location within the data node view container. |
|
参数 Parameters |
|
nodeData T
|
|
index number
|
|
viewContainer? ViewContainerRef
|
|
parentData? T
|
|
renderNodeChanges | |
---|---|
检查数据所做的更改,并渲染每个更改(添加/删除/移动节点)。 Check for changes made in the data and render each change (node added/removed/moved). |
|
参数 Parameters |
|
data T[] | readonly T[]
|
|
dataDiffer IterableDiffer<T> = this._dataDiffer
|
|
viewContainer ViewContainerRef = this._nodeOutlet.viewContainer
|
|
parentData? T
|
|
CdkTreeNode
CdkTree 的树节点。它包含树节点中的数据。
Tree node for CdkTree. It contains the data in the tree node.
属性
名称 | 描述 |
---|---|
|
树节点的数据。 The tree node's data. |
|
|
|
|
@Input()
已弃用
|
树节点的角色是什么。 The role of the tree node. |
方法
focus | |
---|---|
让此菜单项获得焦点。是对 FocusableOption 的实现。 Focuses the menu item. Implements for FocusableOption. |
CdkTreeNodeToggle
切换节点,以展开/折叠节点。
Node toggle to expand/collapse the node.
属性
名称 | 描述 |
---|---|
@Input('cdkTreeNodeToggleRecursive')
|
是否递归展开/折叠节点。 Whether expand/collapse the node recursively. |
类
BaseTreeControl
Base tree control. It has basic toggle/expand/collapse operations on a single data node.
属性
名称 | 描述 |
---|---|
|
Saved data node for |
|
A selection model with multi-selection to track expansion status. |
|
Gets a stream that emits whenever the given data node's children change. |
|
Get depth of a given data node, return the level number. This is for flat tree node. |
|
Whether the data node is expandable. Returns true if expandable. This is for flat tree node. |
|
Returns the identifier by which a dataNode should be tracked, should its reference change. Similar to trackBy for *ngFor |
方法
collapse | |
---|---|
Collapses one single data node. |
|
参数 Parameters |
|
dataNode T
|
|
collapseAll | |
---|---|
Collapse all dataNodes in the tree. |
collapseDescendants | |
---|---|
Collapses a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
expand | |
---|---|
Expands one single data node. |
|
参数 Parameters |
|
dataNode T
|
|
expandAll | |
---|---|
Expands all data nodes in the tree. |
expandDescendants | |
---|---|
Expands a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
getDescendants | |
---|---|
Gets a list of descendent data nodes of a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
T[]
|
|
isExpanded | |
---|---|
Whether a given data node is expanded or not. Returns true if the data node is expanded. |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
boolean
|
|
toggle | |
---|---|
Toggles one single data node's expanded/collapsed state. |
|
参数 Parameters |
|
dataNode T
|
|
toggleDescendants | |
---|---|
Toggles a subtree rooted at |
|
参数 Parameters |
|
dataNode T
|
|
FlatTreeControl
extends
BaseTreeControl
Flat tree control. Able to expand/collapse a subtree recursively for flattened tree.
属性
名称 | 描述 |
---|---|
|
Saved data node for |
|
A selection model with multi-selection to track expansion status. |
|
Gets a stream that emits whenever the given data node's children change. |
|
|
|
|
|
|
|
Returns the identifier by which a dataNode should be tracked, should its reference change. Similar to trackBy for *ngFor |
方法
collapse | |
---|---|
Collapses one single data node. |
|
参数 Parameters |
|
dataNode T
|
|
collapseAll | |
---|---|
Collapse all dataNodes in the tree. |
collapseDescendants | |
---|---|
Collapses a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
expand | |
---|---|
Expands one single data node. |
|
参数 Parameters |
|
dataNode T
|
|
expandAll | |
---|---|
Expands all data nodes in the tree. To make this working, the |
expandDescendants | |
---|---|
Expands a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
getDescendants | |
---|---|
Gets a list of the data node's subtree of descendent data nodes. To make this working, the |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
T[]
|
|
isExpanded | |
---|---|
Whether a given data node is expanded or not. Returns true if the data node is expanded. |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
boolean
|
|
toggle | |
---|---|
Toggles one single data node's expanded/collapsed state. |
|
参数 Parameters |
|
dataNode T
|
|
toggleDescendants | |
---|---|
Toggles a subtree rooted at |
|
参数 Parameters |
|
dataNode T
|
|
NestedTreeControl
extends
BaseTreeControl
Nested tree control. Able to expand/collapse a subtree recursively for NestedNode type.
属性
名称 | 描述 |
---|---|
|
Saved data node for |
|
A selection model with multi-selection to track expansion status. |
|
|
|
Get depth of a given data node, return the level number. This is for flat tree node. |
|
Whether the data node is expandable. Returns true if expandable. This is for flat tree node. |
|
|
|
Returns the identifier by which a dataNode should be tracked, should its reference change. Similar to trackBy for *ngFor |
方法
collapse | |
---|---|
Collapses one single data node. |
|
参数 Parameters |
|
dataNode T
|
|
collapseAll | |
---|---|
Collapse all dataNodes in the tree. |
collapseDescendants | |
---|---|
Collapses a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
expand | |
---|---|
Expands one single data node. |
|
参数 Parameters |
|
dataNode T
|
|
expandAll | |
---|---|
Expands all dataNodes in the tree. To make this working, the |
expandDescendants | |
---|---|
Expands a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
getDescendants | |
---|---|
Gets a list of descendant dataNodes of a subtree rooted at given data node recursively. |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
T[]
|
|
isExpanded | |
---|---|
Whether a given data node is expanded or not. Returns true if the data node is expanded. |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
boolean
|
|
toggle | |
---|---|
Toggles one single data node's expanded/collapsed state. |
|
参数 Parameters |
|
dataNode T
|
|
toggleDescendants | |
---|---|
Toggles a subtree rooted at |
|
参数 Parameters |
|
dataNode T
|
|
CdkTreeNodeOutletContext
提供给树节点组件的上下文。
Context provided to the tree node component.
属性
名称 | 描述 |
---|---|
|
该节点的数据。 Data for the node. |
|
所有数据节点的长度。 Length of the number of total dataNodes. |
|
该节点的索引位置。 Index location of the node. |
|
该节点的深度。 Depth of the node. |
接口
FlatTreeControlOptions
Optional set of configuration that can be provided to the FlatTreeControl.
属性
名称 | 描述 |
---|---|
|
NestedTreeControlOptions
Optional set of configuration that can be provided to the NestedTreeControl.
属性
名称 | 描述 |
---|---|
|
TreeControl
Tree control interface. User can implement TreeControl to expand/collapse dataNodes in the tree.
The CDKTree will use this TreeControl to expand/collapse a node.
User can also use it outside the <cdk-tree>
to control the expansion status of the tree.
属性
名称 | 描述 |
---|---|
|
The saved tree nodes data for |
|
The expansion model |
|
Gets a stream that emits whenever the given data node's children change. |
|
Get depth of a given data node, return the level number. This is for flat tree node. |
|
Whether the data node is expandable. Returns true if expandable. This is for flat tree node. |
方法
collapse | |
---|---|
Collapse one data node |
|
参数 Parameters |
|
dataNode T
|
|
collapseAll | |
---|---|
Collapse all the dataNodes in the tree |
collapseDescendants | |
---|---|
Collapse a data node and all its descendants |
|
参数 Parameters |
|
dataNode T
|
|
expand | |
---|---|
Expand one data node |
|
参数 Parameters |
|
dataNode T
|
|
expandAll | |
---|---|
Expand all the dataNodes in the tree |
expandDescendants | |
---|---|
Expand a data node and all its descendants |
|
参数 Parameters |
|
dataNode T
|
|
getDescendants | |
---|---|
Get all descendants of a data node |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
any[]
|
|
isExpanded | |
---|---|
Whether the data node is expanded or collapsed. Return true if it's expanded. |
|
参数 Parameters |
|
dataNode T
|
|
返回值 Returns |
|
boolean
|
|
toggle | |
---|---|
Expand or collapse data node |
|
参数 Parameters |
|
dataNode T
|
|
toggleDescendants | |
---|---|
Toggle a data node by expand/collapse it and all its descendants |
|
参数 Parameters |
|
dataNode T
|
|