[英]Show content according to dropdown selection
我有一个 object 列表说[{country:"US",name:"ABC"},{country:"China",name:"PQR"},{country:"AUS",name:"XYZ"}]
我想在下拉选择中显示列表的内容。 就像如果我 select 一个国家“美国”只有“ABC”应该来。
我做了下拉菜单,在 state 中,我将所选国家/地区保存为selectedCountry
如何根据selectedCountry
显示名称。
export default function Test() {
let data = [
{ country: "US", name: "ABC" },
{ country: "China", name: "PQR" },
{ country: "AUS", name: "XYZ" },
];
const [selectedCountry, setSelectedCountry] = useState("")
return (
<>
<div>
<select value={selectedCountry} onChange={(e)=>setSelectedCountry(e.target.value)}>
{data.map((item)=>{
return <option value={item.name}>{item.country}</option>
})}
</select>
<p>{selectedCountry}</p>
</div>
</>
);
}
const filtersArray= countryArray.filter(country=> country ===selectedCountry); 国家=过滤数组0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.