【发布时间】:2021-07-06 06:14:12
【问题描述】:
我有一个用于添加国家/地区呼叫代码的自动完成组件,但是,相关国家/地区也随之添加。就像单击自动完成下拉列表时一样,会显示所有国家及其特定代码。我的意图是只添加国家代码。请参阅下面的代码以供参考
const [countryData, setCountryData] = useState({});
const [newValue, setNewValue] = useState("");
useEffect(() => {
setCountryData(codes);
}, []);
<Autocomplete
id="size-small-standard"
size="small"
options={cities}
onChange={(event, value) => setNewValue(value)}
autoSelect={true}
getOptionLabel={(option) =>
option.country + " " + ` +` + option.calling_code {/* <-- How to display only calling code, but, should show both country name and calling code in drop down */}
}
defaultValue={cities[98]}
style={{ width: "100%" }}
renderInput={(params) => (
<TextField
{...params}
variant="standard"
placeholder="Search your country"
style={{ width: "40%" }}
/>
)}
/>
最好的解决方案是什么?
以下是 CodeSandbox 链接:https://codesandbox.io/s/material-demo-forked-3ljj2
【问题讨论】:
标签: reactjs material-ui