Hi,
How i will make a function syncronous.
After calling a function i have some lines of code. But i want that after calling the function completely i should able to execute the bellow lines of code.
Code:
DGPPrefFilterStore.load({
params : {prefName : prefName},
scope : this,
callback: function(records, operation, success) {
var RegionPrefStr=DGPPrefFilterStore.last().data.region;
selectedRegion = RegionPrefStr.split(",");
controller.populateSubRegionAndCountry(selectedRegion);//function in another controller shown bellow
var regionDisplayField = Ext.getCmp('regionTip');
controller.setDisplayField(selectedRegion,regionDisplayField,maxRegion);
var subRegionPrefStr=DGPPrefFilterStore.last().data.subRegion;
selectedSubRegion = subRegionPrefStr.split(",");
var subRegionDisplayField = Ext.getCmp('subRegionTip');
console.log("before pref dispaly gield"+selectedSubRegion);//should prin 2nd but printing first
}
});
populateSubRegionAndCountry : function(selectedRegion){
var subRegionStore = Ext.data.StoreManager.lookup('deliveryGroupPerformances.SubRegionStore');
var countryStore = Ext.data.StoreManager.lookup('deliveryGroupPerformances.CountryStore');
selectedProcessingRegion = [];
subRegionStore.removeAll();
if(selectedRegion.length == 0 || selectedRegion.length == maxRegion){
selectedProcessingRegion = "All";
}
else{
selectedProcessingRegion.length = 0;
for(var i = 0; i < selectedRegion.length; i++)
selectedProcessingRegion.push("'"+selectedRegion[i]+"'");
}
alert(selectedProcessingRegion);
subRegionStore.load({
params : {region : selectedProcessingRegion},
scope : this,
callback: function(records, operation, success)
this.defaultSubRegion(); //calling to a defaultSubRegion function given bellow in same controller
}
});
},
defaultSubRegion : function(){
var subRegionStore = Ext.data.StoreManager.lookup('deliveryGroupPerformances.SubRegionStore');
maxSubRegion = subRegionStore.getCount();
subRegionStore.queryBy(function(record) {
selectedSubRegion.push(record.get('subRegion'));
});
var subRegionDisplayField = Ext.getCmp('subRegionTip');
console.log("before default dispaly field"+selectedSubRegion);//print satement should come firsr
},
Hierarchy is inside a callback() i have called populateSubRegionAndCountry() and have a print statement(say X). Inside the populateSubRegionAndCountry() there is another function which is calling defaultSubRegion() and inside defaultSubRegion() ihave another print statement(say Y).
so i want to print X and then Y syncronously but getting the Y printed first then X
How i make it syncronous call.