我想根據另一個選擇列表更改在intl-Tel-Input中選擇的國家。例如如果在國家選擇列表中選擇馬來西亞,則應將國際電話輸入更改爲馬來西亞,並應顯示其國旗和代碼。相似的,如果國家改爲美國,國際電話輸入應相應改變。從另一個選擇列表更改intlTelInput的國家
任何幫助表示讚賞。
問候。
我想根據另一個選擇列表更改在intl-Tel-Input中選擇的國家。例如如果在國家選擇列表中選擇馬來西亞,則應將國際電話輸入更改爲馬來西亞,並應顯示其國旗和代碼。相似的,如果國家改爲美國,國際電話輸入應相應改變。從另一個選擇列表更改intlTelInput的國家
任何幫助表示讚賞。
問候。
我只想創造JS對象「之類的JSON格式的」包含所有國家代碼有特定的名稱,並動態地試圖改變輸入佔位一次選擇的國家使用JavaScript
如果您正在使用陣營匹配,這裏是解決方案
constructor(){
super()
this.state = {
updated:true
}
}
要跟蹤國家是否正在更改。
componentWillReceiveProps(nextProps){
if(this.props.selectedCountry !== nextProps.selectedCountry){
this.setState({
updated:false
})
}
}
告訴你它要改變現在
componentDidUpdate(nextProps){
if(this.props.selectedCountry !== nextProps.selectedCountry){
this.setState({
updated:true
})
}
}
現在已經改變。
render(){
const { selectedCountry } = this.props;
var countryCode = 'us'
if(selectedCountry)
countryCode = selectedCountry.toLowerCase()
var field = <Field
className="ibm-fullwidth urx-country"
name="phone"
onInputChange={this.onInputChange}
component={this.renderPhoneInput}
defaultCountry={countryCode}
/>
return (
<span>
{this.state.updated &&
<span>{field}</span>
}
</span>
)
}
基本上它是重新渲染國家變化。