场景:管理后台,多个选择框,内容取决于后台接口返回的内容。
后台返回接口中,包含多个数组,且数组中各对象的属性相同,除一个不同。
一、定义并初始化数组
interface A{
aa:string,
ab:string
}
inter B{
ba:string |null,
bb:string | null
}
iterface C{
cA:A[] | null,
cB:B[] | null,
cC:A[] | null,
cD:A[] |null
}
const [d,setD]:[C,Function]=useState({
cA:[],
cB:[],
cC:[],
cD:[]
})
二、赋值 :setD(后台结果)
三、界面显示
<Select placeholder="请选择">
{
d.cA.map(item => {
return <Option value={item.val} key={item.code}>{item.name}</Option>
})
}
</Select>