Skip to content

Instantly share code, notes, and snippets.

@AmyrAhmady
Created July 29, 2019 09:27
Show Gist options
  • Save AmyrAhmady/0061e4e5b2e1a5c55c4409e0fe4be346 to your computer and use it in GitHub Desktop.
Save AmyrAhmady/0061e4e5b2e1a5c55c4409e0fe4be346 to your computer and use it in GitHub Desktop.
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