fix: 修复切换选项可能报修改只读属性的问题

This commit is contained in:
2betop 2023-05-15 17:30:11 +08:00
parent 216b0ab5b5
commit 216a3a9e42

View File

@ -210,6 +210,7 @@ export class TreeSelector extends React.Component<
unfolded: WeakMap<Object, boolean> = new WeakMap();
// key: child option, value: parent option;
relations: WeakMap<Option, Option> = new WeakMap();
levels: WeakMap<Option, number> = new WeakMap();
dragNode: Option | null;
dropInfo: IDropInfo | null;
@ -287,6 +288,11 @@ export class TreeSelector extends React.Component<
}
}
componentWillUnmount(): void {
// clear data
this.relations = this.unfolded = this.levels = new WeakMap() as any;
}
/**
*
*/
@ -877,11 +883,9 @@ export class TreeSelector extends React.Component<
flattenedOptions.push(item);
} else if (this.isUnfolded(parent)) {
this.relations.set(item, parent);
this.levels.set(item, level);
// 父节点是展开的状态
flattenedOptions.push({
...item,
level
});
flattenedOptions.push(item);
}
}
);
@ -1102,7 +1106,7 @@ export class TreeSelector extends React.Component<
? 'folder'
: 'file'
: false);
const level = item.level ? item.level - 1 : 0;
const level = this.levels.has(item) ? this.levels.get(item)! - 1 : 0;
let body = null;