forked from p96170835/amis
expand 改成 findTree
This commit is contained in:
parent
531fbc94e3
commit
5cb489fac8
|
@ -13,7 +13,7 @@ import Downshift, {ControllerStateAndHelpers} from 'downshift';
|
||||||
import {closeIcon, Icon} from './icons';
|
import {closeIcon, Icon} from './icons';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import matchSorter from 'match-sorter';
|
import matchSorter from 'match-sorter';
|
||||||
import {noop, isObject} from '../utils/helper';
|
import {noop, isObject, findTree} from '../utils/helper';
|
||||||
import find from 'lodash/find';
|
import find from 'lodash/find';
|
||||||
import isPlainObject from 'lodash/isPlainObject';
|
import isPlainObject from 'lodash/isPlainObject';
|
||||||
import union from 'lodash/union';
|
import union from 'lodash/union';
|
||||||
|
@ -84,19 +84,24 @@ export function value2array(
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
.map((value: any) => expandValue(value, props))
|
.map((value: any) => expandValue(value, props.options, props.valueField))
|
||||||
.filter((item: any) => item) as Array<Option>;
|
.filter((item: any) => item) as Array<Option>;
|
||||||
} else if (Array.isArray(value)) {
|
} else if (Array.isArray(value)) {
|
||||||
value = value[0];
|
value = value[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
let expandedValue = expandValue(value as OptionValue, props);
|
let expandedValue = expandValue(
|
||||||
|
value as OptionValue,
|
||||||
|
props.options,
|
||||||
|
props.valueField
|
||||||
|
);
|
||||||
return expandedValue ? [expandedValue] : [];
|
return expandedValue ? [expandedValue] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function expandValue(
|
export function expandValue(
|
||||||
value: OptionValue,
|
value: OptionValue,
|
||||||
props: Pick<OptionProps, 'valueField' | 'options'>
|
options: Options,
|
||||||
|
valueField = 'value'
|
||||||
): Option | null {
|
): Option | null {
|
||||||
const valueType = typeof value;
|
const valueType = typeof value;
|
||||||
|
|
||||||
|
@ -108,15 +113,13 @@ export function expandValue(
|
||||||
return value as Option;
|
return value as Option;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {options} = props;
|
|
||||||
|
|
||||||
if (!options) {
|
if (!options) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return find(
|
return findTree(
|
||||||
options,
|
options,
|
||||||
optionValueCompare(value, props.valueField || 'value')
|
optionValueCompare(value, valueField || 'value')
|
||||||
) as Option;
|
) as Option;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue