Skip to content

Commit 3238797

Browse files
committed
fix: improve recursion logic in _tree2array function
1 parent c249c5a commit 3238797

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/helper/convert.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ function _tree2array(tree, options = {}) {
116116
const res = [];
117117
function recurse(data, parent_id) {
118118
data.forEach(d => {
119-
const child = d[c.child_name].map(i => i);
120-
delete d[c.child_name];
119+
if (is.array(d[c.child_name])) {
120+
const child = d[c.child_name].map(i => i);
121+
delete d[c.child_name];
122+
if (child.length) {
123+
recurse(child, d[c.data_index]);
124+
}
125+
}
121126
d[c.parent_index] = parent_id || 0;
122127
res.push(d);
123-
if (child.length) {
124-
recurse(child, d[c.data_index]);
125-
}
126128
});
127129
}
128130
recurse(tree, 0);

0 commit comments

Comments
 (0)