Extjs sets a unique ID for each component otherwise an error occurs

  • 2020-03-30 03:21:02
  • OfStack

Extjs sets a unique ID for each component, otherwise it will cause all kinds of errors

EXTJS basically USES an ID to identify components. If you have a textfield with an ID:"keyword" in panel1 and a textfield with the same ID in panel2, then when you close panel2, it will not be destroyed because EXTJS finds that the ID:"keyword" component in panel2 is still in use in panel1, so it becomes an isolated object, causing confusion.

In any case, keep in mind that you must make sure that the object ID is unique at all times. There are two ways to do this:

1, do not give the object an ID, then use the component's find method to find the object by other attributes, such as find("name","role"), the result is an array, of course, your property is unique, so you can refer to the component in the form of find("name","role")[0].

2. You can also specify child components in the form of parent component ID+ child component ID, which is a better method, and extjs does this internally, where the ID of the child component becomes :this.id+"_role", notice that this refers to the parent component. At instance time, because the ID of the parent component must be unique, even if the same component is instantiated twice, the child component of both instances has a unique ID. Thus ID duplication can be handled well

Related articles: