PDA

View Full Version : Improvement for initRef, this.ref



NeonMonk
14 Nov 2010, 2:09 AM
Hi All,

To make my life easier I wanted to group certain items from their this.ref into an object within their parent. Rather than coming straight off the parent.

At first I naturally assumed that "../blah/item" would achieve that. It doesn't.

This makes it so it does:

*note: this code was thrown together quickly (deadline looming) if you've got a better way to do it, please share.


Ext.override(Ext.Component,{
initRef: function() {
if(this.ref && !this.refOwner){
var levels = this.ref.split('../'),
last = levels.length,
i = 0,
t = this;

while(t && i < last){
t = t.ownerCt;
++i;
}
if(t){
var l = levels[--i].split('/'),
x = 0;
while (l[x]) {
if (!n) {
var n = t;
}
if (l[x+1]) {
n[l[x]] = n[l[x]] || {};
n = n[l[x]];
} else {
n[this.refName = l[x]] = this;
}
x++;
}
/**
* @type Ext.Container
* @property refOwner
* The ancestor Container into which the {@link #ref} reference was inserted if this Component
* is a child of a Container, and has been configured with a <code>ref</code>.
*/
this.refOwner = t;
}
}
}
});

This doesn't take into account removeRef, as I've never had a need to ever use that. But I'm sure it wouldn't be too difficult to alter that to work with this.

devtig
15 Nov 2010, 11:41 AM
very similar: http://www.sencha.com/forum/showthread.php?109127-Suggested-extension-to-Ext-refs