diff --git a/packages/semi-foundation/tree/constants.ts b/packages/semi-foundation/tree/constants.ts index 3e91c2d6de..a0dba6bd66 100644 --- a/packages/semi-foundation/tree/constants.ts +++ b/packages/semi-foundation/tree/constants.ts @@ -7,6 +7,7 @@ const cssClasses = { const strings = { EXPAND_ACTION: [false, 'click', 'doubleClick'], + JSON_KEY_SPLIT: '_SEMI_TREE_SPLIT_', }; const numbers = {}; diff --git a/packages/semi-foundation/tree/foundation.ts b/packages/semi-foundation/tree/foundation.ts index eb11d45051..540c98f943 100644 --- a/packages/semi-foundation/tree/foundation.ts +++ b/packages/semi-foundation/tree/foundation.ts @@ -23,6 +23,7 @@ import { } from './treeUtil'; import type { KeyMapProps } from './treeUtil'; +import { strings } from './constants'; export type { KeyMapProps }; export interface BasicTreeNodeProps { @@ -415,7 +416,7 @@ export default class TreeFoundation extends BaseFoundation i.replace('-', '.')); + const selectedPath = normalizedArr(key).map(i => i.replaceAll(strings.JSON_KEY_SPLIT, '.')); const value = pick(data, selectedPath); this._adapter.notifyChange(value as BasicValue); } diff --git a/packages/semi-foundation/tree/treeUtil.ts b/packages/semi-foundation/tree/treeUtil.ts index c8eff086c0..a7b4c1b80c 100644 --- a/packages/semi-foundation/tree/treeUtil.ts +++ b/packages/semi-foundation/tree/treeUtil.ts @@ -4,6 +4,7 @@ */ import { difference, uniq, max, isObject, isNull, isUndefined, isEmpty, pick, get, omit } from 'lodash'; +import { strings } from './constants'; export interface KeyEntities { [x: string]: any @@ -98,7 +99,7 @@ export function convertJsonToData(treeJson: TreeDataSimpleJson) { const treeData: any[] = []; const traverseNode = (key: string, children: any, path: any, res: any[]) => { const currPath = [...path, key]; - const itemKey = currPath.join('-'); + const itemKey = currPath.join(strings.JSON_KEY_SPLIT); const newNode: NodeData = { key: itemKey, diff --git a/packages/semi-ui/tree/_story/tree.stories.jsx b/packages/semi-ui/tree/_story/tree.stories.jsx index 6ec495ff5a..fb0a3f2a1c 100644 --- a/packages/semi-ui/tree/_story/tree.stories.jsx +++ b/packages/semi-ui/tree/_story/tree.stories.jsx @@ -276,8 +276,13 @@ const treeDataWithNode = [ const treeJson = { Node1: { - Child1: '0-0-1', - Child2: '0-0-2', + Child1: { + child11: '0-0-1', + child12: '0-0-2' + }, + Child2: { + child21: '0-1-1', + }, }, Node2: '0-1', }; @@ -2926,7 +2931,7 @@ export const KeyMaps = () => { }, []); const normalExpanded = useCallback((expandedKeys, { expanded, node }) => { - console.log('onExpanded', expandedKeys, expanded, cloneDeep(node)); + console.log('onExpanded', expandedKeys, expanded, copy(node)); }, []);