mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 14:16:26 +00:00
fix: fix judge an empty object
This commit is contained in:
parent
0125ae8df9
commit
5e472796c6
@ -9,16 +9,18 @@ import { defaultFieldNames, getCurrentOptions } from './shared';
|
|||||||
|
|
||||||
type Props = SelectProps<any, any> & { objectValue?: boolean; onChange?: (v: any) => void };
|
type Props = SelectProps<any, any> & { objectValue?: boolean; onChange?: (v: any) => void };
|
||||||
|
|
||||||
|
const isEmptyObject = (val: any) => !isValid(val) || (typeof val === 'object' && Object.keys(val).length === 0);
|
||||||
|
|
||||||
const ObjectSelect = (props: Props) => {
|
const ObjectSelect = (props: Props) => {
|
||||||
const { value, options, onChange, fieldNames, mode, ...others } = props;
|
const { value, options, onChange, fieldNames, mode, ...others } = props;
|
||||||
const toValue = (v: any) => {
|
const toValue = (v: any) => {
|
||||||
if (!isValid(v)) {
|
if (isEmptyObject(v)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const values = toArr(v).map((val) => {
|
const values = toArr(v).map((val) => {
|
||||||
return typeof val === 'object' ? val[fieldNames.value] : val;
|
return typeof val === 'object' ? val[fieldNames.value] : val;
|
||||||
});
|
});
|
||||||
const current = getCurrentOptions(values, options, fieldNames).map((val) => {
|
const current = getCurrentOptions(values, options, fieldNames)?.map((val) => {
|
||||||
return {
|
return {
|
||||||
label: val[fieldNames.label],
|
label: val[fieldNames.label],
|
||||||
value: val[fieldNames.value],
|
value: val[fieldNames.value],
|
||||||
|
Loading…
Reference in New Issue
Block a user