PDA

View Full Version : Getting a component xtype path



zombeerose
18 Jan 2012, 12:40 PM
Does anybody know of an efficient way to get the absolute path of a component's xtype that includes the parent hierarchy when given an element?

For example, I have a viewport that contains an extended panel for authenticating (xtype: 'panel_login') that contains a button. If I catch an event that was targeted on the button element, I would like to be able to calculate that the path is "viewport panel_login button."

This is one specific example but I'm looking for a generic pattern that could work for any element/component.

Thanks!

skirtle
18 Jan 2012, 8:42 PM
What do you mean by 'element'? Do you mean an HTML element or component?

From the component it should just be this:


var comp = ...;
var xtypes = [];

while (comp) {
xtypes.unshift(comp.getXType());
comp = comp.ownerCt;
}

var path = xtypes.join(' ');

From an HTML element things get much more complicated. In general there's no way to map from an element back to a component. You could approximate it but I can't think of an efficient algorithm for it.

I'm a little unclear about why you would need to do this.

zombeerose
19 Jan 2012, 7:42 AM
I am trying to write some help documentation for my product. Since a given component may be used multiple times across different "applications," I am trying to uniquely identify the particular usage by the respective chain of xtypes. Since the help may be initiated by a key event, I have to start with the target element (html/ext) and go from there to get a component.