mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Cascader): assignKey function deep clone Array (#8326)
Co-authored-by: nemo-shen <1034131477@qq.com>
This commit is contained in:
parent
869b9a66c6
commit
bf1652e938
@ -1,12 +1,22 @@
|
|||||||
import { deepAssign } from './deep-assign';
|
import { isDef } from './index';
|
||||||
|
import { ObjectIndex } from './types';
|
||||||
|
|
||||||
|
export function deepClone(obj: ObjectIndex): object {
|
||||||
|
if (!isDef(obj)) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
export function deepClone(obj: object): object {
|
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
return obj.map((item) => deepClone(item));
|
return obj.map((item) => deepClone(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof obj === 'object') {
|
if (typeof obj === 'object') {
|
||||||
return deepAssign({}, obj);
|
const to = {} as ObjectIndex;
|
||||||
|
Object.keys(obj).forEach((key) => {
|
||||||
|
to[key] = deepClone(obj[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user