Ritika
Ritika

Reputation: 593

Iterate datastore in Sencha touch & edit record

I am using Sencha touch v 2.3.0 for my hybrid cordova app. How can we loop through Sencha touch data store & update each record?

for (var x = 0 ;x <listStore.data.length;x++){
        var record = listStore.getAt(x);
            console.log('iterate rec at index:'+x+ ' fav list name:'+record.get('favorite_name')+'orderInd:'+record.get('order_index'));
            record.set('order_index',x);
            record.dirty = true;
            listStore.sync();

        });  

This will update 1st record only correct, after that when i update 2nd record, that still have reference to 1st record.Also i have applied sorting on data store with field order_index as ASC. This data store is used on list for which i have enabled drag & sort.I have to do this update ondragsort function

onDragSort:function(list, row, from, to) {
var listStore = Ext.getStore('FavoriteListStore');
    for (x = 0 ;x <listStore.data.length;x++){
        console.log('before drag fav list name:'+listStore.data.items[x].get('favorite_name')+'orderInd:'+listStore.data.items[x].get('order_index'));
    }
for (var x = 0 ;x <listStore.data.length;x++){
        var record = listStore.getAt(x);
            console.log('iterate rec at index:'+x+ ' fav list name:'+record.get('favorite_name')+'orderInd:'+record.get('order_index'));
            record.set('order_index',x);
            record.dirty = true;
            listStore.sync();

        });
}

Initial my favorite list store have following data

name:Steel order_index:0
name:Sample Favorite List order_index:1
name:Electrical Essentials order_index:2

Above data is shown on list,now when i drag third row on list to bring it to top. Below is console when i try to set order_index by iteration

before drag fav list name:Electrical Essentials orderInd:2 before drag fav list name:Steel orderInd:0 before drag fav list name:Sample Favorite List orderInd:1

After setting order_index by iteration , below is data on data store while iteration iterate rec at index:0 fav list name:Electrical EssentialsorderInd:2 iterate rec at index:1 fav list name:Electrical EssentialsorderInd:0 iterate rec at index:2 fav list name:Electrical EssentialsorderInd:1

I am confused on why record is not fetched correctly when i am doing iterate & updating orderInd.Intially before set , record where fetched correctly

Upvotes: 0

Views: 57

Answers (0)

Related Questions