Created
July 29, 2019 09:27
-
-
Save AmyrAhmady/0061e4e5b2e1a5c55c4409e0fe4be346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchCities() { | |
fetch(global.apiURL + '/index/city?id=all') | |
.then((response) => response.json()) | |
.then((responseJson) => { | |
this.tempData.cities = responseJson; | |
this.fetchStates(); | |
}) | |
.catch((error) => { | |
console.error(error); | |
alert("خطا در ارتباط با سرور! لیست شهر ها یافت نشد"); | |
//this.setState({ loadingState: false }); | |
}); | |
} | |
fetchStates() { | |
fetch(global.apiURL + '/index/state') | |
.then((response) => response.json()) | |
.then((responseJson) => { | |
this.tempData.states = responseJson; | |
}) | |
.catch((error) => { | |
console.error(error); | |
alert("خطا در ارتباط با سرور! لیست استان ها یافت نشد"); | |
//this.setState({ loadingState: false }); | |
}); | |
} | |
mixStatesAndCities() { | |
this.globalData.mapData = this.tempData.states; | |
for (var key in this.tempData.states) { | |
let result = this.tempData.cities.filter(element => { | |
if (element.state_id === this.tempData.states[key].id) { | |
return element | |
} | |
}); | |
this.globalData.mapData[key].cities = result; | |
} | |
global.appData = this.globalData; | |
this.setState({ loadingState: false }); | |
} | |
////////////////////////////////////////////////////////////////// | |
ostan : | |
<MenuList | |
data={global.appData.mapData} | |
onChange={(option) => { | |
this.setState({ currentCityList: option.cities }); | |
this.inputs.adProvince = option.id; | |
}} | |
closeText="بستن" /> | |
///////////////////////////////////////////////////////////////// | |
city: | |
<MenuList | |
style={{ height: 40 }} | |
data={this.state.currentCityList} | |
onChange={(option) => { | |
this.inputs.adCity = option.id; | |
}} | |
closeText="بستن" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment