mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复切换选项可能报修改只读属性的问题
This commit is contained in:
parent
216b0ab5b5
commit
216a3a9e42
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user