{ label: '省关联', field: 'provinceId', colProps: { span: 12 }, component: 'ApiSelect', componentProps: ({ formActionType }) => { return { api: optionSegmentApi, showSearch: true, optionFilterProp: 'label', resultField: 'items', labelField: 'name', valueField: 'id', onChange: async (e: any) => { const cityList = await optionCityApi(e); const { updateSchema } = formActionType; updateSchema({ field: 'cityId', componentProps: { options: [] }, // reset options here }); updateSchema({ field: 'cityId', componentProps: { options: cityList, labelField: 'name', valueField: 'id', }, }); console.log('cityList', cityList); // move the log statement here }, }; }, }, { label: '市关联', field: 'cityId', component: 'Select', componentProps: { showSearch: true, optionFilterProp: 'label', }, colProps: { span: 12 }, },获取不到市关联的列表
时间: 2024-02-14 13:10:24 浏览: 34
根据你提供的代码,我看到在 `onChange` 函数中,已经调用了 `optionCityApi` 函数来获取城市列表,并将其赋值给了 `cityList`。然后通过 `updateSchema` 函数更新了 `cityId` 的选项,但是你说无法获取到市关联的列表,可能是因为你没有将 `cityId` 的选项正确地传递给 `Select` 组件。
你可以在 `cityId` 的 `componentProps` 中指定 `options` 为 `componentProps.options`,而不是将其设置为一个空数组。这样,当你更新了 `cityId` 的选项时,`Select` 组件将自动重新渲染,并显示新的选项。你还需要指定 `labelField` 和 `valueField` 属性,以确保正确地显示选项的标签和值。
修改后的代码如下:
```
{
label: '省关联',
field: 'provinceId',
colProps: { span: 12 },
component: 'ApiSelect',
componentProps: ({ formActionType }) => {
return {
api: optionSegmentApi,
showSearch: true,
optionFilterProp: 'label',
resultField: 'items',
labelField: 'name',
valueField: 'id',
onChange: async (e: any) => {
const cityList = await optionCityApi(e);
const { updateSchema } = formActionType;
updateSchema({
field: 'cityId',
componentProps: {
options: cityList,
labelField: 'name',
valueField: 'id',
},
});
console.log('cityList', cityList); // move the log statement here
},
};
},
},
{
label: '市关联',
field: 'cityId',
component: 'Select',
componentProps: {
showSearch: true,
optionFilterProp: 'label',
options: [],
labelField: 'name',
valueField: 'id',
},
colProps: { span: 12 },
}
```