Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search组件TreeSelect控件配置optionApi显示“无数据” #342

Closed
hzzdong opened this issue Sep 21, 2023 · 6 comments
Closed

Search组件TreeSelect控件配置optionApi显示“无数据” #342

hzzdong opened this issue Sep 21, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@hzzdong
Copy link

hzzdong commented Sep 21, 2023

FormSchema[]配置:
[{
field: 'bookTypeId',
label: t('book.bookTypeId'),
component: 'TreeSelect',
componentProps: {
nodeKey: 'id',
props: {
label: 'name'
}
},
optionApi: async () => {
const res = await getTreeListApi({} as IListRequest)
return res.data
}
},...]
Search组件TreeSelect控件配置optionApi显示“无数据”。
但是Form组件同样配置,TreeSelect控件配置optionApi缺可以正常下拉选择数据。

@hzzdong
Copy link
Author

hzzdong commented Sep 21, 2023

发现问题是在Search组件中不会自动调用optionApi得到的结果赋值给componentProps!.data。

@kailong321200875 kailong321200875 added the bug Something isn't working label Sep 22, 2023
@bobohuochai
Copy link

遇到同样的问题,可以在父组件里操作Search 组件的schema,临时解决下。

这里奇怪的地方是,在Form 组件里更改了自己的Schema 数组深层属性,这个做法在vue 里其实是不推荐的。
不知道为什么Form 可以生效,而在Search 里不生效,Search 其实也是更改Form 的属性。

@hzzdong
Copy link
Author

hzzdong commented Sep 22, 2023

遇到同样的问题,可以在父组件里操作Search 组件的schema,临时解决下。

这里奇怪的地方是,在Form 组件里更改了自己的Schema 数组深层属性,这个做法在vue 里其实是不推荐的。 不知道为什么Form 可以生效,而在Search 里不生效,Search 其实也是更改Form 的属性。

看了下源码,Form在渲染formItem的时候调用了:
// 渲染formItem
const renderFormItem = (item: FormSchema) => {
// 如果有optionApi,优先使用optionApi
if (item.optionApi) {
// 内部自动调用接口,不影响其它渲染
getOptions(item.optionApi, item)
}
..........
}

const getOptions = async (fn: Function, item: FormSchema) => {
const options = await fn()
setSchema([
{
field: item.field,
path:
item.component === ComponentNameEnum.TREE_SELECT
? 'componentProps.data'
: 'componentProps.options',
value: options
}
])
}
而Search组件找不到类似功能的代码。

@bobohuochai
Copy link

遇到同样的问题,可以在父组件里操作Search 组件的schema,临时解决下。

这里奇怪的地方是,在Form 组件里更改了自己的Schema 数组深层属性,这个做法在vue 里其实是不推荐的。 不知道为什么Form 可以生效,而在Search 里不生效,Search 其实也是更改Form 的属性。

看了下源码,Form在渲染formItem的时候调用了: // 渲染formItem const renderFormItem = (item: FormSchema) => { // 如果有optionApi,优先使用optionApi if (item.optionApi) { // 内部自动调用接口,不影响其它渲染 getOptions(item.optionApi, item) } .......... }

const getOptions = async (fn: Function, item: FormSchema) => { const options = await fn() setSchema([ { field: item.field, path: item.component === ComponentNameEnum.TREE_SELECT ? 'componentProps.data' : 'componentProps.options', value: options } ]) } 而Search组件找不到类似功能的代码。

Search 也是用了Form
image

@hzzdong
Copy link
Author

hzzdong commented Sep 22, 2023

遇到同样的问题,可以在父组件里操作Search 组件的schema,临时解决下。

这里奇怪的地方是,在Form 组件里更改了自己的Schema 数组深层属性,这个做法在vue 里其实是不推荐的。 不知道为什么Form 可以生效,而在Search 里不生效,Search 其实也是更改Form 的属性。

看了下源码,Form在渲染formItem的时候调用了: // 渲染formItem const renderFormItem = (item: FormSchema) => { // 如果有optionApi,优先使用optionApi if (item.optionApi) { // 内部自动调用接口,不影响其它渲染 getOptions(item.optionApi, item) } .......... }
const getOptions = async (fn: Function, item: FormSchema) => { const options = await fn() setSchema([ { field: item.field, path: item.component === ComponentNameEnum.TREE_SELECT ? 'componentProps.data' : 'componentProps.options', value: options } ]) } 而Search组件找不到类似功能的代码。

Search 也是用了Form image

对啊。奇怪。

@whosphp
Copy link
Contributor

whosphp commented Sep 26, 2023

我也遇到了同样的问题

checkboxGroup 这个如果使用了 optionApi 懒加载数据, 传入 Search 组件就会渲染不出来 option,
但是如果传入 Form 组件就是正常的.

const formSchema = reactive<FormSchema[]>([
  {
    label: 'aaa',
    field: 'aaa',
    component: 'CheckboxGroup',
    optionApi: async () => {
      return [
        {
          label: 'a',
          value: 'a'
        },
        {
          label: 'b',
          value: 'b'
        }
      ]
    }
  }
])

<Search :schema="formSchema" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants