Skip to content

Commit 76583cf

Browse files
committed
fix: pid null
1 parent 70c4b91 commit 76583cf

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/HeTree.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,25 @@ export function useHeTree<T extends Record<string, any>>(
9696
const rootNodes: T[] = []
9797
const rootStats: Stat<T>[] = []
9898
//
99-
function* simpleWalk(): Generator<T> {
99+
function* simpleWalk() {
100100
if (props.dataType === 'flat') {
101101
for (const node of props.data) {
102-
yield node
102+
yield [node]
103103
}
104104
} else {
105-
for (const [node] of walkTreeDataGenerator(props.data, CHILDREN)) {
106-
yield node
105+
for (const t of walkTreeDataGenerator(props.data, CHILDREN)) {
106+
yield t
107107
}
108108
}
109109
}
110110
let count = 0
111-
for (const node of simpleWalk()) {
111+
for (const [node, info] of simpleWalk()) {
112112
const id: Id = node[ID] ?? count
113-
const pid = node[PID] as Id
114-
const parent = nodes[pid] || null
113+
let pid = node[PID] as Id
114+
if (props.dataType === 'tree') {
115+
pid = info.parent?.[ID] ?? null
116+
}
117+
let parent = nodes[pid] || null
115118
const parentStat = stats[pid] || null;
116119
const childIds: Id[] = []
117120
const children: T[] = []

0 commit comments

Comments
 (0)