我有一组数据,我想通过这些数据来更新UI select option
,但我不知道该怎么做
JSON数据
[
{
country: 'India',
cities: [
{
city_name: 'New delhi',
},
{
city_name: 'mumbai',
},
],
},
{
country: 'England',
cities: [
{
city_name: 'London',
},
{
city_name: 'manchester',
},
],
},
{
country: 'Portugal',
cities: [
{
city_name: 'Lisbon',
},
],
},
];
我尝试过的是:
<select
name="country">
{data.map((li, index) => (
<option
key={index}
value={li.country}
onchange={() => onchange_device(li.country)}>
{li.country}
</option>
))}
</select>
<select
name="city">
<option
value="city val
>
here I want to show city
</option>
))}
</select>
我正在尝试进行换乘,但首先我想显示第一个选项处于选中状态,然后还要选择子城市,我不知道该怎么做