Hybrid View

  1. #1
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Question Looping through a DataStore

    Looping through a DataStore


    Having set up a datastore, how does one loop through, accessing all the elements e.g. given

    Code:
    for(var i=0;i<ds.getTotalCount();i++){
    ....
    
    }

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750
    Vote Rating
    9
    fay will become famous soon enough fay will become famous soon enough

      0  

    Post


    I've done it as follows:

    Code:
    for (var i = 0; i < ds.getCount(); i++)
    {
      if (ds.getAt(i).data.isselected) // isselected is a field in my store
        s += ' ' + ds.data.items[i].id; 
    }
    Ext.MessageBox.alert('Results', s);

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Posts
    7,854
    Vote Rating
    4
    tryanDLS is on a distinguished road

      0  

    Default


    You could use the each method, or getRange(0, count-1). The data property isn't really public , but it's equivalent to the getRange call

  4. #4
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Thumbs up


    Cheers fay and Tim

  5. #5
    Ext User
    Join Date
    Mar 2007
    Posts
    5
    Vote Rating
    0
    Eric_ht is on a distinguished road

      0  

    Default Looping through store..infinite loop?

    Looping through store..infinite loop?


    Using the above example posted by Fay, I get an infinite loop. Since i begins at 0, which is the beginning record address for the datastore and getCount() returns the actual number of records (1 if 1 exists), i will always be less than getCount...or am I missing something here?

  6. #6
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,527
    Vote Rating
    379
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Use each method as recommended by Tim. Veeeery easy.

  7. #7
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750
    Vote Rating
    9
    fay will become famous soon enough fay will become famous soon enough

      0  

    Default


    Hi Eric,

    I was incrementing i in the for loop (i++), but I now also use the each() method which I never knew existed before! My jaw has repetitive strain injury from thanking Tim I really can't get over the amount of time and effort that these guys/gals put into helping us!