fix(amis-core): 修复select组件中一个未判空导致的渲染错误 (#6937)

* fix(amis-core): 修复select组件中一个未判空导致的渲染错误

* fix(amis-core): 修复select组件中一个未判空导致的渲染错误
This commit is contained in:
刘丹 2023-05-19 21:51:39 +08:00 committed by GitHub
parent 0f63e1bbbc
commit a36502b311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,32 +52,37 @@ export function normalizeOptions(
return option;
});
} else if (Array.isArray(options as Options)) {
return (options as Options).map(item => {
const value = item && item[valueField];
return (options as Options)
.filter(item => item !== null && item !== undefined)
.map(item => {
const value = item && item[valueField];
const idx =
value !== undefined && !item.children
? share.values.indexOf(value)
: -1;
const idx =
value !== undefined && !item.children
? share.values.indexOf(value)
: -1;
if (~idx) {
return share.options[idx];
}
if (~idx) {
return share.options[idx];
}
const option = {
...item,
[valueField]: value
};
const option = {
...item,
[valueField]: value
};
if (typeof option.children !== 'undefined') {
option.children = normalizeOptions(
option.children,
share,
valueField
);
} else if (value !== undefined) {
share.values.push(value);
share.options.push(option);
}
if (typeof option.children !== 'undefined') {
option.children = normalizeOptions(option.children, share, valueField);
} else if (value !== undefined) {
share.values.push(value);
share.options.push(option);
}
return option;
});
return option;
});
} else if (isPlainObject(options)) {
return Object.keys(options).map(key => {
const idx = share.values.indexOf(key);