fix(Variable): fix can not select
This commit is contained in:
parent
0a21c3bed2
commit
b7cb9a45c2
@ -1,6 +1,6 @@
|
|||||||
import { observable } from '@formily/reactive';
|
import { observable } from '@formily/reactive';
|
||||||
import { error } from '@nocobase/utils/client';
|
import { error } from '@nocobase/utils/client';
|
||||||
import { useMemo } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { useCompile, useGetFilterOptions } from '../../../schema-component';
|
import { useCompile, useGetFilterOptions } from '../../../schema-component';
|
||||||
import { FieldOption, Option } from '../type';
|
import { FieldOption, Option } from '../type';
|
||||||
|
|
||||||
@ -49,6 +49,8 @@ const getChildren = (options: FieldOption[], { schema, depth, maxDepth, loadChil
|
|||||||
export const useUserVariable = ({ schema, maxDepth = 3 }: { schema: any; maxDepth?: number }) => {
|
export const useUserVariable = ({ schema, maxDepth = 3 }: { schema: any; maxDepth?: number }) => {
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const getFilterOptions = useGetFilterOptions();
|
const getFilterOptions = useGetFilterOptions();
|
||||||
|
const schemaRef = useRef(schema);
|
||||||
|
schemaRef.current = schema;
|
||||||
|
|
||||||
const loadChildren = (option: Option): Promise<void> => {
|
const loadChildren = (option: Option): Promise<void> => {
|
||||||
if (!option.field?.target) {
|
if (!option.field?.target) {
|
||||||
@ -63,7 +65,7 @@ export const useUserVariable = ({ schema, maxDepth = 3 }: { schema: any; maxDept
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const children =
|
const children =
|
||||||
getChildren(getFilterOptions(collectionName), {
|
getChildren(getFilterOptions(collectionName), {
|
||||||
schema,
|
schema: schemaRef.current,
|
||||||
depth: option.depth + 1,
|
depth: option.depth + 1,
|
||||||
maxDepth,
|
maxDepth,
|
||||||
loadChildren,
|
loadChildren,
|
||||||
@ -90,7 +92,7 @@ export const useUserVariable = ({ schema, maxDepth = 3 }: { schema: any; maxDept
|
|||||||
depth: 0,
|
depth: 0,
|
||||||
loadChildren,
|
loadChildren,
|
||||||
} as Option);
|
} as Option);
|
||||||
}, [schema]);
|
}, []);
|
||||||
|
|
||||||
// 必须使用 observable 包一下,使其变成响应式对象,不然 children 加载后不会更新 UI
|
// 必须使用 observable 包一下,使其变成响应式对象,不然 children 加载后不会更新 UI
|
||||||
return observable(result);
|
return observable(result);
|
||||||
|
Loading…
Reference in New Issue
Block a user