vendredi 19 septembre 2014

Wait processing Store.records to complete before store.sync

Hi,

I noticed that SYNC method behaves differently when the Record's field values are set 'individually' (changed), rather than using form.updateRecord(record)


It seems SYNC 'waits' for form.updateRecord(record) to complete but not during individual field settings...

Or maybe that form.updateRecord(record) is faster than individually setting the field values thus it seems to 'wait'.


Nevertheless, how can we be sure that all the Store's record (hundreds or thousands) are completely processed (values of form fields (or cell fields of a datagrid) are transferred to Records) before the SYNC batch method is called?


I have the code below, which I transferred the SYNC method in and out of the for loop. Behavior is intermittent and I don't know what's the best way to do so.



Code:



var addressStore = Ext.getStore('personAddress');
var form = Ext.getCmp('borrowerRightPanel1').down('#residenceForm');
console.log("store count is = " + addressStore.count());

for (var i = 0 ; i < addressStore.count() ; i++){
var typeID = parseInt(addressStore.getAt(i).get('TYPE_ID'));
if (typeID === 0){
fieldSet = form.down('#currentAddress');
} else if (typeID === 1) {
fieldSet = form.down('#previousAddress');
}
addressStore.getAt(i).set('NO_STREET_VILLAGE',fieldSet.down('#addressNoStreetVillage').getValue());
addressStore.getAt(i).set('BARANGAY', fieldSet.down('#addressBarangay').getValue());
addressStore.getAt(i).set('CITY_MUNICIPALITY',fieldSet.down('#addressCityMunicipality').getValue());
addressStore.getAt(i).set('PROVINCE', fieldSet.down('#addresProvince').getValue());
addressStore.getAt(i).set('REGION', fieldSet.down('#addressRegion').getValue());
addressStore.getAt(i).set('OWNERSHIP', fieldSet.down('#addressOwnership').getValue());
addressStore.getAt(i).set('STAYED_SINCE', fieldSet.down('#addressStayedSince').getValue());
addressStore.getAt(i).set('TOTAL_YEAR', fieldSet.down('#addressTotalYear').getValue());
addressStore.getAt(i).set('TOTAL_MONTH', fieldSet.down('#addressTotalMonth').getValue());
}

addressStore.sync({
success: function(batch, eOpts) {
console.log(batch.operations[0].request.scope.reader.jsonData['message']); },
failure: function(batch) {
console.log(batch.operations[0].request.scope.reader.jsonData['message']);
}
});





Wait processing Store.records to complete before store.sync

Aucun commentaire:

Enregistrer un commentaire