Skip to content

Commit 851f677

Browse files
authored
docs: 更新getChildrenData方法文档,修正返回值类型并添加使用注意事项 (#7123)
1 parent cdaeae6 commit 851f677

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/site/docs/api/data.en.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ const comboParent = graph.getParentData('node1', 'combo');
327327
Get the data of child elements of a node or combo.
328328

329329
```typescript
330-
getChildrenData(id: ID): NodeLikeData[];
330+
getChildrenData(id: ID): (NodeData \| ComboData)[];
331331
```
332332

333333
**Parameters**:
@@ -338,9 +338,14 @@ getChildrenData(id: ID): NodeLikeData[];
338338

339339
**Return Value**:
340340

341-
- **Type**: NodeData \| ComboData[]
341+
- **Type**: (NodeData \| ComboData)[]
342342
- **Description**: Returns an array of child element data
343343

344+
**Note**:
345+
346+
- **Querying combo's child elements**: If the id corresponds to a combo element, you can directly use this API to get all its child elements.
347+
- **Querying node's child elements**: If the id corresponds to a node, only when the graph data is a tree structure (i.e., the node data maintains a `children` field, and `children` is an array of child node IDs for that node), can you use this API to get the child elements of that node. Otherwise, an empty array is returned.
348+
344349
**Example**:
345350

346351
```typescript

packages/site/docs/api/data.zh.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ const comboParent = graph.getParentData('node1', 'combo');
327327
获取节点或组合的子元素数据。
328328

329329
```typescript
330-
getChildrenData(id: ID): NodeLikeData[];
330+
getChildrenData(id: ID):(NodeData \| ComboData)[];
331331
```
332332

333333
**参数**:
@@ -338,9 +338,14 @@ getChildrenData(id: ID): NodeLikeData[];
338338

339339
**返回值**:
340340

341-
- **类型**: NodeData \| ComboData[]
341+
- **类型**: (NodeData \| ComboData)[]
342342
- **描述**: 返回子元素数据数组
343343

344+
**注意**:
345+
346+
- **查询 combo 的子元素**:如果 id 对应的是 combo 元素,可以直接通过此 API 获取其所有子元素。
347+
- **查询节点的子元素**:如果 id 对应的是节点,只有当图数据为树结构(即节点数据中维护有 `children` 字段,且 `children` 为该节点的子节点 ID 数组)时,才能通过此 API 获取到该节点的子元素。否则返回空数组。
348+
344349
**示例**:
345350

346351
```typescript

0 commit comments

Comments
 (0)