React Antd pro 中 ProFormDependency 和 ProFormSelect 组合使用遇到的问题

ProFormDependency 和 ProFormSelect 组合使用时,不是每次修改依赖值都会触发ProFormSelect 的request远程请求函数。

代码:

<ProFormDependency name={['attendance_org_id']}>
  {({ attendance_org_id }) => {  // 1处
    return (
      <ProFormSelect
        debounceTime={300}
        name="dayoff_id"
        showSearch
        label='标题'
        rules={[{ required: true, message: formatMessage({ id: 'component.required' }) }]}
        request={async () => {
          let arr: any = [];
          if (attendance_org_id) {   // 这里直接使用 1处 的变量,导致不是每次都会监听到
            let res = await queryByOrgId({org_id: attendance_org_id});
            if (res && res.data) {
              arr = res.data.map((v: any) => {
                return {
                  label: v.name,
                  value: v.id
                };
              });
            }
          }
          return arr;
        }}
      />
    );
  }}
</ProFormDependency>

问题:参数不能直接使用,要使用params传入,修改后的代码:

<ProFormDependency name={['attendance_org_id']}>
  {({ attendance_org_id }) => {
    return (
      <ProFormSelect
        debounceTime={300}
        name="dayoff_id"
        showSearch
        label='标题'
        rules={[{ required: true, message: formatMessage({ id: 'component.required' }) }]}
        params={
  { attendance_org_id }}  // 使用params属性,传入request
        request={async ({ attendance_org_id }) => {  // request使用params传入的参数,每次都触发了
          let arr: any = [];
          if (attendance_org_id) {
            let res = await queryByOrgId({org_id: attendance_org_id});
            if (res && res.data) {
              arr = res.data.map((v: any) => {
                return {
                  label: v.name,
                  value: v.id
                };
              });
            }
          }
          return arr;
        }}
      />
    );
  }}
</ProFormDependency>

相关推荐

  1. Element-plus使用遇到问题

    2023-12-08 10:22:01       13 阅读
  2. 实际工作kafka应用遇到问题

    2023-12-08 10:22:01       15 阅读
  3. cocos creator开发遇到问题解决方案

    2023-12-08 10:22:01       13 阅读
  4. 面试遇到VUE问题

    2023-12-08 10:22:01       26 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-08 10:22:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-08 10:22:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-08 10:22:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-08 10:22:01       18 阅读

热门阅读

  1. Groovy介绍和使用

    2023-12-08 10:22:01       27 阅读
  2. ES6数据处理函数(笔记)

    2023-12-08 10:22:01       31 阅读
  3. VUE.js

    2023-12-08 10:22:01       32 阅读
  4. 移除、混淆静态库中多余的符号(待续)

    2023-12-08 10:22:01       39 阅读
  5. 九、C#笔记

    2023-12-08 10:22:01       30 阅读