0

I have three variables: foo, bar, and test.

They are the following objects: an Ext.Component, an Ext.Element, and an HTMLElement (or a DOM node).

  1. How would you identify which one is which? E.g. foo.isExtElement()

  2. How would you find other two related objects for every variable? E.g. find corresponding Ext.Element and HTMLElement given you already know that foo is an Ext.Component. And so on.

(I can't add an [htmlelement] tag due to low reputation)

EDIT:

Added example to #1 and as per @kevhender replaced "convert" with "find".

Geo
  • 12,666
  • 4
  • 40
  • 55

1 Answers1

2

The question itself doesn't really make sense. You wouldn't ever "convert" any of these into another... These are 3 different, distinct types of variables, each with their own purpose.

I've already addressed the differences between these three types in my answer to your last question: https://stackoverflow.com/a/18855938/2072693

I wouldn't call these a "conversion", but here are the ways to get one of these types from another:

component.getEl()  //gets the Ext.Element of the top level of the component
component.getEl().dom  //gives the HTMLElement of the top level of the component
element.dom   //gets the HTMLElement from the Ext.Element
Ext.get(htmlElement)  //allows for using Ext.Element methods on an HTMLElement

There is no built-in way to get an Ext.Component from an Ext.Element or HTMLElement -- in fact, it wouldn't really make sense.

Community
  • 1
  • 1
kevhender
  • 4,285
  • 1
  • 13
  • 16
  • okay, not "convert". I meant to find element knowing a component, and vice versa. You got it right. Why finding a component wouldn't make sense? What about `Ext.getDom()`? – Geo Sep 25 '13 at 17:41
  • It doesn't make sense because there isn't a 1:1 ratio of components to elements. Components are drawn on the screen with any number of Elements, so only having the element wouldn't guarantee that it corresponds to a component. Also, I've never used `Ext.getDom()`, but it just looks like another helper method that could definitely be used for similar functionality to what my answer says. – kevhender Sep 25 '13 at 17:56
  • so there are elements that might relate to *more than one* component? – Geo Sep 25 '13 at 18:14
  • Sure, if they are nested... but that's not really what I was saying. The point is that when the framework renders its components, it will create any number of elements necessary to render that component. So, unless you knew for sure that the element you have was the top-level element generated for the component, you wouldn't be able to get the component from the element (you technically could, with some clever selectors tricks... but not something I've done). – kevhender Sep 25 '13 at 18:31