react+ant-design-proTable 设置搜索条件中的默认值
需求:
这个规则组ID的 下拉列表是通过向后端请求获取的,如何设置自定义渲染列表,并且默认有值
let groupLists = [] as any, //规则组列表 defaultValue = ''; //默认值 const formRef = useRef(); const columns: ProColumns [] = [ { title: '规则组ID', dataIndex: 'rGroupId', valueType: 'select', initialValue: defaultValue, renderFormItem: (_, { defaultRender }) => { return ( ); } }, ]; /**useEffect */ useEffect(() => { getGroupList(); }, []); /**function */ const getGroupList = async (): Promise => { let reqParams = { page: 1, size: 99999, search: '' }; await ruleApi .getGroupList(reqParams) .then((res) => { let { content } = res && res.data; groupLists = content; defaultValue = groupLists.length ? groupLists[0].id : ''; formRef.current?.setFieldsValue({ //这个formRef作用在ProTable标签上,如下图 rGroupId: defaultValue }); }) .catch((err) => console.log(err)); };