首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法从react-phone-input-2/material-ui-phone-number中选择的标志中获取国家信息(代码)

有没有办法从react-phone-input-2/material-ui-phone-number中选择的标志中获取国家信息(代码)
EN

Stack Overflow用户
提问于 2019-12-24 05:16:35
回答 2查看 1.3K关注 0票数 1

我使用的是https://www.npmjs.com/package/material-ui-phone-number包,它是从react-phone-input包中开发的,希望获得从下拉菜单中选择的旗帜上的国家代码基础。这有可能吗?我确实看到了对象' country‘的详细信息,但我无法获得国家代码。

代码语言:javascript
复制
<MuiPhoneNumber value={phone || ''} defaultCountry={'us'}  preferredCountries={['gb', 'us']} disableAreaCodes={true} value={phone || ''} onChange={handleOnChange} />

我只能在onChange中获得目标值

EN

回答 2

Stack Overflow用户

发布于 2021-07-08 02:17:49

正如您在material-ui-phone-number中的supported events中看到的那样

代码语言:javascript
复制
<MuiPhoneNumber onChange={(value, country) => console.log(country)} />

第二个参数将为您提供一个国家数据对象,其中包括:name,dialCode,country code

也是

未从onKeyDown event返回

国家/地区数据对象

票数 0
EN

Stack Overflow用户

发布于 2021-03-03 04:42:09

我自己也遇到了这个问题,弄清楚了……

代码语言:javascript
复制
{<MuiPhoneNumber value={phone || ''} defaultCountry={'us'}  preferredCountries={['gb', 'us']} disableAreaCodes={true} value={phone || ''} onChange={(country) => handleOnChange(country.countryCode)} />}

只需将country传递给onchange并使用country.countryCode获取代码,或者使用country.name获取名称,使用country.dialCode获取拨号代码。

干杯

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59461383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档