PDA

View Full Version : 4.0.1 doc issue in Ext.data.Store (getById)



meditecsports
26 May 2011, 11:03 PM
In Ext.data.Store the method "getById" documentation claims, that undefined, would be
returned, when nothing was found. (Was true in ExtJS3). However, in ExtJS4, it returns null.
Here is why:


/**
* Get the Record with the specified id.
* @param {String} id The id of the Record to find.
* @return {Ext.data.Model} The Record with the passed id. Returns undefined if not found.
*/
getById: function(id) {
return (this.snapshot || this.data).findBy(function(record) {
return record.getId() === id;
});
},

...which uses...


findBy : function(fn, scope) {
var keys = this.keys,
items = this.items,
i = 0,
len = items.length;

for (; i < len; i++) {
if (fn.call(scope || window, items[i], keys[i])) {
return items[i];
}
}
return null;
},

returning null, in case of "not found"