MCPcopy
hub / github.com/baidu/amis / getVariable

Function getVariable

packages/amis-core/src/utils/getVariable.ts:3–23  ·  view source on GitHub ↗
(
  data: {[propName: string]: any},
  key: string | undefined,
  canAccessSuper: boolean = true
)

Source from the content-addressed store, hash-verified

1import {keyToPath} from './keyToPath';
2
3export function getVariable(
4 data: {[propName: string]: any},
5 key: string | undefined,
6 canAccessSuper: boolean = true
7): any {
8 if (!data || !key || typeof data !== 'object') {
9 return undefined;
10 } else if (canAccessSuper ? key in data : data.hasOwnProperty(key)) {
11 return data[key];
12 }
13
14 return keyToPath(key).reduce(
15 (obj, key) =>
16 obj &&
17 typeof obj === 'object' &&
18 (canAccessSuper ? key in obj : obj.hasOwnProperty(key))
19 ? obj[key]
20 : undefined,
21 data
22 );
23}

Callers 15

renderSelectionMethod · 0.90
componentDidMountMethod · 0.90
componentDidUpdateMethod · 0.90
renderTagMethod · 0.90
componentDidUpdateMethod · 0.90
renderPdfMethod · 0.90
renderFormFileMethod · 0.90
componentDidUpdateMethod · 0.90
exportExcelFunction · 0.90
doActionMethod · 0.90
doActionMethod · 0.90
validateMethod · 0.90

Calls 1

keyToPathFunction · 0.90

Tested by

no test coverage detected