forked from p96170835/amis
Options extractValue 用法优化
This commit is contained in:
parent
53b7905c50
commit
9432ec9ef4
|
@ -213,6 +213,7 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
|
||||
if (prevProps.options !== props.options && formItem) {
|
||||
formItem.setOptions(normalizeOptions(props.options || []));
|
||||
this.normalizeValue();
|
||||
} else if (
|
||||
config.autoLoadOptionsFromSource !== false &&
|
||||
props.source &&
|
||||
|
@ -232,6 +233,8 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
);
|
||||
prevOptions !== options &&
|
||||
formItem.setOptions(normalizeOptions(options || []));
|
||||
|
||||
this.normalizeValue();
|
||||
} else if (
|
||||
isEffectiveApi(props.source, props.data) &&
|
||||
isApiOutdated(
|
||||
|
@ -241,17 +244,17 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
props.data
|
||||
)
|
||||
) {
|
||||
formItem.loadOptions(
|
||||
props.source,
|
||||
props.data,
|
||||
undefined,
|
||||
true,
|
||||
props.onChange
|
||||
);
|
||||
formItem
|
||||
.loadOptions(
|
||||
props.source,
|
||||
props.data,
|
||||
undefined,
|
||||
true,
|
||||
props.onChange
|
||||
)
|
||||
.then(() => this.normalizeValue());
|
||||
}
|
||||
}
|
||||
|
||||
this.normalizeValue();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -339,7 +342,7 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
let valueArray = formItem.getSelectedOptions(value).concat();
|
||||
const idx = findIndex(
|
||||
valueArray,
|
||||
optionValueCompare(option.value, valueField || 'value')
|
||||
optionValueCompare(option[valueField || 'value'], valueField || 'value')
|
||||
);
|
||||
let newValue: string | Array<Option> | Option = '';
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ export default class Form extends React.Component<FormProps, object> {
|
|||
const hooks: Array<(data: any) => Promise<any>> = this.hooks['init'] || [];
|
||||
await Promise.all(hooks.map(hook => hook(data)));
|
||||
|
||||
if (store.initedAt !== initedAt) {
|
||||
if (isAlive(store) && store.initedAt !== initedAt) {
|
||||
// 说明,之前的数据已经失效了。
|
||||
// 比如 combo 一开始设置了初始值,然后 form 的 initApi 又返回了新的值。
|
||||
// 这个时候 store 的数据应该已经 init 了新的值。但是 data 还是老的,这个时候
|
||||
|
|
|
@ -169,7 +169,14 @@ export const FormItemStore = types
|
|||
) {
|
||||
unMatched = {
|
||||
[self.valueField || 'value']: item,
|
||||
[self.labelField || 'label']: item
|
||||
[self.labelField || 'label']: item,
|
||||
'__unmatched': true
|
||||
};
|
||||
} else if (unMatched && self.extractValue) {
|
||||
unMatched = {
|
||||
[self.valueField || 'value']: item,
|
||||
[self.labelField || 'label']: 'UnKnown',
|
||||
'__unmatched': true
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -534,6 +541,12 @@ export const FormItemStore = types
|
|||
unMatched[self.labelField || 'label'] =
|
||||
orgin[self.labelField || 'label'];
|
||||
}
|
||||
} else if (unMatched && self.extractValue) {
|
||||
unMatched = {
|
||||
[self.valueField || 'value']: item,
|
||||
[self.labelField || 'label']: 'UnKnown',
|
||||
'__unmatched': true
|
||||
};
|
||||
}
|
||||
|
||||
unMatched && selectedOptions.push(unMatched);
|
||||
|
|
Loading…
Reference in New Issue