File tree 1 file changed +10
-7
lines changed
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -96,22 +96,25 @@ export function useHeTree<T extends Record<string, any>>(
96
96
const rootNodes : T [ ] = [ ]
97
97
const rootStats : Stat < T > [ ] = [ ]
98
98
//
99
- function * simpleWalk ( ) : Generator < T > {
99
+ function * simpleWalk ( ) {
100
100
if ( props . dataType === 'flat' ) {
101
101
for ( const node of props . data ) {
102
- yield node
102
+ yield [ node ]
103
103
}
104
104
} 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
107
107
}
108
108
}
109
109
}
110
110
let count = 0
111
- for ( const node of simpleWalk ( ) ) {
111
+ for ( const [ node , info ] of simpleWalk ( ) ) {
112
112
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
115
118
const parentStat = stats [ pid ] || null ;
116
119
const childIds : Id [ ] = [ ]
117
120
const children : T [ ] = [ ]
You can’t perform that action at this time.
0 commit comments