bixi
Version:
企业级中后台前端解决方案
24 lines (21 loc) • 683 B
text/typescript
import { NzSafeAny } from 'ng-zorro-antd/core/types';
export const getValue = (target: NzSafeAny, key: string): NzSafeAny => {
const keys = typeof key === 'string' ? key.split('.') : [key];
key = '';
do {
key += keys.shift();
if (isDefined(target) && isDefined(target[key]) && (typeof target[key] === 'object' || !keys.length)) {
target = target[key];
key = '';
} else if (!keys.length) {
target = undefined;
} else {
key += '.';
}
} while (keys.length);
if (target === undefined) return '-';
return target;
};
export function isDefined(value: NzSafeAny): boolean {
return typeof value !== 'undefined' && value !== null;
}