Skip to content

Commit

Permalink
feat(TreeData): 新增 exportList 方法导出一维列表数据
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Dec 14, 2020
1 parent 20eecb1 commit 66cf34d
Show file tree
Hide file tree
Showing 3 changed files with 871 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/utils/TreeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ describe('TreeData', () => {
expect(new TreeData(data).clone().export()).toMatchSnapshot()
})

test('exportList', () => {
expect(new TreeData(data).exportList()).toMatchSnapshot()
})

test('fromList', () => {
expect(
TreeData.fromList(
Expand Down
13 changes: 12 additions & 1 deletion src/utils/TreeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,18 @@ export class TreeData<TNode extends TreeDataNode> {
}

/**
* 从列表生成实例。
* 导出一维列表数据。
*/
exportList(): TNode[] {
const list: TNode[] = []
this.traverse(payload => {
list.push(payload.node)
})
return cloneDeep(list)
}

/**
* 从一维列表生成实例。
*
* @param list 列表
* @param idKey ID 所在键
Expand Down
Loading

0 comments on commit 66cf34d

Please sign in to comment.