ant-design/pro-components

🐛 [BUG] ProFormSelect 中传递了默认值,但没有渲染在显示区域中

Opened this issue · 0 comments

🐛 bug 描述

ProFormSelect 中传递了默认值,但没有渲染在显示区域中,并且显示区域是空的,连占位符都没有显示,这说明可能有值但没有被正确渲染

📷 复现步骤 | Recurrence steps

运行代码

🏞 期望结果 | Expected results

正确设置初始值

💻 复现代码 | Recurrence code

import { GetCategories } from '@/services/api/category';
import { SelectOptionType } from '@/typings';
import { ProFormSelect, ProFormSelectProps } from '@ant-design/pro-components';
import { BaseOptionType } from 'antd/es/select';
import React from 'react';

const ProformSelectCategory = <T, OptionType extends BaseOptionType = any>(
	props: ProFormSelectProps<T, OptionType>,
): React.ReactElement => {
	const fetchCategoryList = async ({ keyWords }: { keyWords: string; }): Promise<SelectOptionType[]> => {
		// if (!keyWords) return [];

		console.debug('<ProformSelectCategory> 搜索的关键字: ', keyWords, props.initialValue);

		try {
			const data = await GetCategories();
			return data.map((it): SelectOptionType => {
				return { label: it.name!, value: it.id!, key: it.id };
			});
		} catch (e) {
			console.debug('没有找到该分类');
			return [];
		}
	};

	return (
		<ProFormSelect<T, OptionType>
			fieldProps={{
				labelInValue: true,
			}}
			{...props}
			request={fetchCategoryList}
		/>
	);
};

export default ProformSelectCategory;

© 版本信息

  • Ant Design Pro 版本: 2.6.48
  • umi 版本 2.2.2
  • 浏览器环境 Edge
  • 开发环境 Windows Edge

🚑 其他信息

image

补充 props.initialValue 的值是一个数字类型的id,对应 { label: it.name!, value: it.id!, key: it.id };中的 value 和 key