Results 1 to 3 of 3

Thread: Possible inconsistency with Store's filterBy and getById methods

  1. #1
    Sencha User
    Join Date
    Feb 2008
    Posts
    39
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Feb 2008
    Posts
    39
    Vote Rating
    1
      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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •