ReactJs:如何在 RegionDropdown 中選擇默認值。我正在使用“react-country-region-selector”,其中有兩個組件“CountryDropdown”和“RegionDropdown”。現在在構造函數中,我選擇了默認值“CountryDropdown”。但我的要求是,當我從國家/地區列表中選擇任何值時,regionDropdown 將使用列表中的第一個名稱的默認值填充。這是我嘗試過的代碼:第 1 步:導入 react-country-region-selector第 2 步:在我的代碼中使用這些組件。在構造函數中,我設置了 country country 的初始值:'United States'這是我瀏覽過的鏈接:https://www.npmjs.com/package/react-country-region-selector#demoimport { CountryDropdown, RegionDropdown, CountryRegionData } from 'react-country-region-selector';<tr> <td><label><CountryDropdown value={this.state.country} onChange={(val) => this.selectCountry(val)} /> </label> </td> <td><label><RegionDropdown country={this.state.country} value={this.state.region}onChange={(val) => this.selectRegion(val)}/> </label> </td></tr> selectCountry (val) { this.setState({ country: val }); } selectRegion (val) { this.setState({ region: val }); }//And in the constructor i set the initial value of country country: 'United States'我期望的是默認情況下“RegionDropdown”將始終與列表中的第一個值一起出現。例如:渲染時它將是“阿拉巴馬”,因為默認國家是“美國”。
ReactJs:如何在 RegionDropdown 中選擇默認值
qq_遁去的一_1
2021-08-20 15:45:40