Search code examples
javascriptextjstouch

Weird situation when retrieving data from sencha datastore


I am having a weird situation when retrieving some data from my datastore. A user can take a walk with my app and save this route. He can save multiple routes if the user wanted to.

I save my coords in a coords store and i retrieve them like this:

var coordsStore = Ext.getStore("CoordsStore");

first i check if my store has some records:

if(coordsStore.getCount() > 0)

When true i will loop these through and check the route

 for(var i = 0; i < coordsStore.getCount(); i++){

        var model = coordsStore.getData().getAt(i);    
        var routeModel = model.get("route");
  }

on the first run this goes how it is supposed to go and returns all records with route 0.

when going for a second run (route 1 in this case) the coords store returns strange values. Instead of expecting also the route 0 coords AND route 1 coords , we only get back the route 1 coords.

What getting my attention is when looking at coordsStore.getData().getAt(i);

the data.all contains:

enter image description here

the data.items contains:

enter image description here

you see that the route value is different, when using a getAt somehow he is using the values from data.items and not from data.all.

Any Ideas how i can retrieve the data from data.all?


Solution

  • Usually working with store records i prefer getting them after a load of the store, you should try like this.

    coordsStore.reload(function(records){ //callback whit records
         records.forEach(function(record,index){
          //you code
        });
    });
    

    Getting records directly from store object can be a problem, because stores load asyncrounsly.

    remember to call a store.sync() to save changes of your store when modifing