PDA

View Full Version : Why no access to parent configs?!



steve.neill
13 Sep 2007, 12:08 PM
Is it possible to get access to the parent config of an item?

For example, lets say I have a config like this:

...
items: [{
xtype: 'panel',
layout: 'card',
region: 'center',
tbar: [{
text: "menu item",
listeners: {
click: function() { ... }
}
}]
}]
...

When "menu item" is clicked, a function is called in which I need access to the config object of the panel in which the menu item exists.

How do I do that?

I was curious as to why no "ownerCt" property is automatically created for a config object where objects such as "bbar" and "tbar" exist.

Thanks,

Steve

steve.neill
13 Sep 2007, 3:09 PM
This may not be the best approach, and until I learn of a better way to do this I've patched my Ext.js as follows:



Ext.apply = function(o, c, defaults){
if(defaults){
// no "this" reference for friendly out of scope calls
Ext.apply(o, defaults);
}

if(o && c && typeof c == 'object'){
for(var p in c){
o[p] = c[p];
}

var itm;
var typ = ['bbar', 'tbar']; /* and others? */
for(var t = 0; t < typ.length; t++) {
if(itm = c[typ[t]]) {
for(var i = 0; i < itm.length; i++) {
itm[i].ownerCt = typeof itm[i] == 'object' ? o : null;
}
}
}
}

return o;
};


Any feedback from the development team would we welcome on this issue.

Thanks,

Steve

Animal
13 Sep 2007, 11:27 PM
Ext 2.0 has exactly that. A Container, when an item is added to it, sets that item's "ownerCt" property to the Container object.

steve.neill
14 Sep 2007, 10:18 AM
I'm using the latest 2.0 SVN and 'ownerCt' is only available for containers with layout, not for things such as toolbar menu items.

steve.neill
18 Sep 2007, 7:52 AM
Jack, can this property be added to tbars, bbars, and menus please?

steve.neill
25 Sep 2007, 12:26 PM
My revised patch...


Ext.apply = function(o, c, defaults){
if(defaults){
// no "this" reference for friendly out of scope calls
Ext.apply(o, defaults);
}

if(o && c && typeof c == 'object'){
for(var p in c){
o[p] = c[p];
}

var itm;
var typ = ['bbar', 'buttons', 'menu', 'tbar']; /* and others? */

for (var t = 0; t < typ.length; t++) {
if (itm = c[typ[t]]) {
for (var i = 0; i < itm.length; i++) {
if (!itm[i].ownerCt) { // preserve initial ownerCt
itm[i].ownerCt = typeof itm[i] == 'object' ? o : null;
}
}
}
}

}

return o;
};