2016-08-16 39 views
0

我想根据另一个选择列表更改在intl-Tel-Input中选择的国家。例如如果在国家选择列表中选择马来西亚,则应将国际电话输入更改为马来西亚,并应显示其国旗和代码。相似的,如果国家改为美国,国际电话输入应相应改变。从另一个选择列表更改intlTelInput的国家

任何帮助表示赞赏。

问候。

回答

0

我只想创造JS对象“之类的JSON格式的”包含所有国家代码有特定的名称,并动态地试图改变输入占位一次选择的国家使用JavaScript

0

如果您正在使用阵营匹配,这里是解决方案

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> 
    ) 
} 

基本上它是重新渲染国家变化。