fix: currentObject can not loadData (#2385)

This commit is contained in:
katherinehhh 2023-08-03 17:42:26 +08:00 committed by GitHub
parent 05cba94982
commit 316b12a4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,8 +120,9 @@ const ConstantTypes = {
function getTypedConstantOption(type: string, types: true | string[], fieldNames) {
const allTypes = Object.values(ConstantTypes);
const children = (
types ? allTypes.filter((item) => (Array.isArray(types) && types.includes(item.value)) || types === true) : allTypes
const children = (types
? allTypes.filter((item) => (Array.isArray(types) && types.includes(item.value)) || types === true)
: allTypes
).map((item) =>
Object.keys(item).reduce(
(result, key) =>
@ -181,8 +182,10 @@ export function Input(props) {
fieldNames ?? {},
);
const { component: ConstantComponent, ...constantOption }: DefaultOptionType & { component?: React.FC<any> } =
useMemo(() => {
const {
component: ConstantComponent,
...constantOption
}: DefaultOptionType & { component?: React.FC<any> } = useMemo(() => {
if (children) {
return {
value: '',
@ -209,7 +212,7 @@ export function Input(props) {
const loadData = async (selectedOptions: DefaultOptionType[]) => {
const option = selectedOptions[selectedOptions.length - 1];
if (!option.children && !option.isLeaf && option.loadChildren) {
if (!option.children?.length && !option.isLeaf && option.loadChildren) {
await option.loadChildren(option);
setOptions((prev) => [...prev]);
}