1. #1
    Sencha User
    Join Date
    Feb 2008
    Posts
    39
    Vote Rating
    1
    cjauvin is on a distinguished road

      0  

    Default Possible inconsistency with Store's filterBy and getById methods

    Possible inconsistency with Store's filterBy and getById methods


    I'm very new to ST (1.1.1) so I really don't know if this is a bug or a "feature", but it seems suspect to me anyway. When I do a filterBy on a Store, the filtered records are still available with getById afterward:
    Code:
    Ext.setup({
        onReady: function() {
    
            Ext.regModel('person', {
                fields: [{name:'id', type:'int'}, 
                         {name:'name', type:'string'}]
            });
    
            var person_store = new Ext.data.Store({
                model: 'person',
                data: [{id:10, name: 'Christian'},
                       {id:20, name: 'Julie'}]
            });
    
            console.log(person_store.getCount()); // 2
    
            person_store.filterBy(function(rec, id) {
                return rec.get('name') == 'Christian';
            });
    
            console.log(person_store.getCount()); // 1 (as it should, after filterBy)
    
            console.log(person_store.getAt(0)); // person record (Christian)
            console.log(person_store.getAt(1)); // undefined (as it should)
    
            console.log(person_store.getById(10)); // person record (Christian)
            console.log(person_store.getById(20)); // person record (Julie).. why? 
                                                   // it shouldn't be available: it's been filtered out!
    
            // and also..
            console.log(person_store.getById(30)); // null.. why not undefined, as the doc says?
    
        }
    });
    And as the last line shows, there's also the (more minor, although potentially dangerous) inconsistency that getById returns "null" for a nonexistent record, whereas the doc says it should return "undefined" (which would be nicer also because it would be consistent with the behavior of getAt):

    http://docs.sencha.com/touch/1-1/#!/...method-getById

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,812
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    When you filter a Store, there are two datasets... the filtered set and unfiltered set. getById will get from the unfiltered set.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Feb 2008
    Posts
    39
    Vote Rating
    1
    cjauvin is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    When you filter a Store, there are two datasets... the filtered set and unfiltered set. getById will get from the unfiltered set.
    Fair enough, but is this documented somewhere? It is not exactly obvious I'd say.

Thread Participants: 1

Tags for this Thread