ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

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

2026/8/24 17:43:31 拓冰建站 浏览量
React Antd pro 中 ProFormDependency 和 ProFormSelect 组合使用遇到的问题

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

代码:

<ProFormDependency name={['attendance_org_id']}>{({ attendance_org_id }) => {  // 1处return (<ProFormSelectdebounceTime={300}name="dayoff_id"showSearchlabel='标题'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 (<ProFormSelectdebounceTime={300}name="dayoff_id"showSearchlabel='标题'rules={[{ required: true, message: formatMessage({ id: 'component.required' }) }]}params={{ attendance_org_id }}  // 使用params属性,传入requestrequest={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>