PDA

View Full Version : .findParentByType() vs. .findParentBy()



Bunneh
11 Aug 2011, 4:04 AM
I have a weird bug, this chunk of code returns null:

var personalCardContainer = personalCardList.findParentByType(Uhrm.widget.PersonalCardContainer);
But if I replace it with:

var personalCardContainer = personalCardList.findParentBy(function (component)
{
return component instanceof Uhrm.widget.PersonalCardContainer;
});
It returns the desired component. What is the problem?

Uberdude
11 Aug 2011, 5:31 AM
Looking at the source code, findParentByType is implemented as:


findParentByType : function(xtype) {

return Ext.isFunction(xtype) ?
this.findParentBy(function(p){
return p.constructor === xtype;
}) :
this.findParentBy(function(p){
return p.constructor.xtype === xtype;
});
}


So by using the constructor property will only return an item that is precisely that type.

Your custom find function uses instaceof, which will return true if the component is exactly the type listed, or any of its subclasses.

Bunneh
11 Aug 2011, 6:04 AM
The item is returned by

var personalCardContainer = personalCardList.findParentBy(function (component)
{
return component instanceof Uhrm.widget.PersonalCardContainer;
});
is exactly of type Uhrm.widget.PersonalCardContainer.
Actually Uhrm.widget.PersonalCardContainer has no subclasses...

The Uhrm.widget.PersonalCardContainer source code:

Uhrm.widget.PersonalCardContainer = Ext.extend(Ext.TabPanel,
{
constructor: function (config)
{
config = Ext.apply(
{
title: '??????? ??????',
closable: true,
activeTab: 0,
items: new Uhrm.widget.PersonalCardList()
}, config);

Uhrm.widget.PersonalCardContainer.superclass.constructor.call(this, config);
console.info('"PersonalCardContainer" widget object has been successfully constructed!');
}
});

console.info('"PersonalCardContainer" widget class has been successfully loaded!');