ProFormSelect支持搜索查询的写法

例一

<ProFormSelect
    name="select1"
    label="支持搜索查询的 Select1"
    showSearch
    debounceTime={300}
    request={async ({ keyWords }) => {
        await waitTime(100);
        console.log(
            Mock.mock({
                'data|1-2': [
                    {
                        value: '@id',
                        label: '@name',
                    },
                ],
            }).data.concat({
                value: keyWords,
                label: '目标_target',
            }),
        );
        return [
            {
                "value": "370000201709291787",
                "label": "Thomas Williams"
            },
            {
                "value": "410000200905158447",
                "label": "Edward Davis"
            },
            {
                "label": "目标_target"
            }
        ];
    }}
    placeholder="Please select a country"
    rules={[{ required: true, message: 'Please select your country!' }]}
/>

const waitTime = (time: number = 100) => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(true);
        }, time);
    });
};

例二

<ProFormSelect
    name="select2"
    label="支持搜索查询的 Select2"
    showSearch
    debounceTime={300}
    request={async ({ keyWords }) => {
        await waitTime(100);

        const modelList: any[] | PromiseLike<any[]> = [];

        await getInstrumentModelList(
            {
                current: '1',
                pageSize: '20',
                instrumentModelName: keyWords
            }
        ).then((res) => {
            const result = {
                data: res.rows,
                total: res.total,
                success: true,
            };
            // eslint-disable-next-line array-callback-return
            result.data.map(item => {
                modelList.push({ value: item.instrumentModelId.toString(), label: item.instrumentModelName });
            })

        })
        console.log(modelList);
        return modelList;

    }}
    placeholder="Please select a country"
    rules={[{ required: true, message: 'Please select your country!' }]}
/>

modelList = [
    {
        "value": "1",
        "label": "型号名称20230122"
    },
    {
        "value": "3",
        "label": "1212"
    }
]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值