PDA

View Full Version : Possible inconsistency with Store's filterBy and getById methods



cjauvin
20 Nov 2011, 7:49 PM
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:


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/#!/api/Ext.data.Store-method-getById

mitchellsimoens
21 Nov 2011, 9:49 AM
When you filter a Store, there are two datasets... the filtered set and unfiltered set. getById will get from the unfiltered set.

cjauvin
21 Nov 2011, 9:57 AM
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.